Help with a simple script

Discuss and share scripts and script files...
Post Reply
karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Help with a simple script

Post by karimmaster101 »

I'm trying to set a timestamp of multi folders to be similar to a file inside each one of them.
For example:
D:\folder1 have similar dates as D:\folder1\folder1.mp4 file
D:\folder128 have similar dates as D:\folder128\folder128.mp4 file

Here is what I got at first:

Code: Select all

    foreach($item, <get SelectedItemsPathNames |>) {
	timestamp , $item.mp4, $item;
	}
It doesn't work because it ignores the dot (.mp4); I didn't figure a way to escape it.

So, I think that I should use a variable along with RegExReplace but I don't know the proper syntax for such a case.
I know this is logically stupid. So here I am asking for your help

Code: Select all

  $source = RegExReplace("$item", "$", ".mp4");
  foreach($item, <get SelectedItemsPathNames |>) {
		timestamp , $source, $item;
	}
Last edited by karimmaster101 on 20 Oct 2018 08:54, edited 1 time in total.

highend
Posts: 11091
Joined: 06 Feb 2011 00:33

Re: Help with a simple script

Post by highend »

D:\folder1 have similar dates as D:\folder1.mp4 file
But you did notice that this file isn't even inside that folder? So construct the correct path in the loop e.g. with the help of getpathcomponent()
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Help with a simple script

Post by karimmaster101 »

Sorry for this mistake, I edited the post.

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Help with a simple script

Post by karimmaster101 »

Now I got this:

Code: Select all

   foreach($item, <get SelectedItemsPathNames |>) {
        $source = RegExReplace("$item", "$", ".mp4");
	timestamp cm, $source, $item;
	}
But it doesn't work and gives me "Invalid date. <Source file path>".
When I use echo $source it returns the file inside the folder as expected: D:\folder1\folder1.mp4
What am I doing wrong here?
Last edited by karimmaster101 on 21 Oct 2018 05:56, edited 1 time in total.

jupe
Posts: 1735
Joined: 20 Oct 2017 21:14
Location: Win10 21H2 120dpi

Re: Help with a simple script

Post by jupe »

Here is a quick mod of a way to do it,

Code: Select all

	foreach($item, <get SelectedItemsPathNames |>) {
		timestamp , $item . "\" . gpc($item, "file") . ".mp4", $item;
	}

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Help with a simple script

Post by karimmaster101 »

jupe wrote:Here is a quick mod of a way to do it,

Code: Select all

	foreach($item, <get SelectedItemsPathNames |>) {
		timestamp , $item . "\" . gpc($item, "file") . ".mp4", $item;
	}
It works. Many thanks. Though I am wondering why my code doesn't work, Do you have any idea what am I doing wrong?

jupe
Posts: 1735
Joined: 20 Oct 2017 21:14
Location: Win10 21H2 120dpi

Re: Help with a simple script

Post by jupe »

By the looks of it you constructed the path wrong, $source would have been missing the file name, I thought seeing my answer would have hinted at that.

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Help with a simple script

Post by karimmaster101 »

jupe wrote:By the looks of it you constructed the path wrong, $source would have been missing the file name, I thought seeing my answer would have hinted at that.
Aha Now I see. thanks a million for your help

villawow
Posts: 3
Joined: 25 Oct 2021 00:57

Re: Help with a simple script

Post by villawow »

jupe wrote: 21 Oct 2018 05:56 Here is a quick mod of a way to do it,

Code: Select all

	foreach($item, <get SelectedItemsPathNames |>) {
		timestamp , $item . "\" . gpc($item, "file") . ".mp4", $item;
	}
What if I want to get whatever name mp4 inside the selected folder - not same name as parent folder- ? how could that work?
I got that is the part responsible for grabbing the file name
. gpc($item, "file") . ".mp4"
I need to edit this to match any .mp4 file inside.
PS: it will be just one .mp4 inside every folder

jupe
Posts: 1735
Joined: 20 Oct 2017 21:14
Location: Win10 21H2 120dpi

Re: Help with a simple script

Post by jupe »

Not sure I understand what you mean? Do you want to timestamp 1 random named mp4 in each selected folder with the timetamp of the files parent folder? (or vice versa) That is my best guess as to what you are asking, if that is so, then this would be one way to do it:

Code: Select all

  $files = quicksearch("*.mp4 /lpd=1 /fn", <selitems |>);
  foreach($file, $files, <crlf>) { timestamp , gpc($file, "path"), $file; }
If you aren't interested in timestamping and just want to know how to find 1 mp4 in each selected folder, then just use/mod the first line.

villawow
Posts: 3
Joined: 25 Oct 2021 00:57

Re: Help with a simple script

Post by villawow »

jupe wrote: 25 Oct 2021 04:03 Not sure I understand what you mean? Do you want to timestamp 1 random named mp4 in each selected folder with the timetamp of the files parent folder? (or vice versa) That is my best guess as to what you are asking, if that is so, then this would be one way to do it:

Code: Select all

  $files = quicksearch("*.mp4 /lpd=1 /fn", <selitems |>);
  foreach($file, $files, <crlf>) { timestamp , gpc($file, "path"), $file; }
If you aren't interested in timestamping and just want to know how to find 1 mp4 in each selected folder, then just use/mod the first line.
I needed to do the vice versa -timestamp the folder with the same date as the .mp4 inside it. I reversed the both $file and gpc parts, and It works as I needed now. Thanks

Another question If I may ask! My scenario/problem was that I have files (mp4,mov,mkv) and I wanted to give each file a parent folder. So I use this script to move each file to a folder with the same name as the file
foreach($item, <get SelectedItemsPathNames |>, , "e") {
moveto "<curpath>\" . gpc($item, "base"), $item, , 2;
}
Then I encountered the Modified date problem -I need to maintain it as the same as the file itself- and I fortunately found the solution here.

I wonder if there is a smart way to merge the two scripts together To the following job:
Move any selected file (ex:txt,mp4,mp3,mov,flv,mkv,...) to a separated folder with the same name of the file and the same Modified/Created Date

highend
Posts: 11091
Joined: 06 Feb 2011 00:33

Re: Help with a simple script

Post by highend »

Store the current created / modified date in a variable before the move and then use these values for the timestamping afterwards?

Look up the property() script command in the help file
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

villawow
Posts: 3
Joined: 25 Oct 2021 00:57

Re: Help with a simple script

Post by villawow »

highend wrote: 25 Oct 2021 10:27 Store the current created / modified date in a variable before the move and then use these values for the timestamping afterwards?

Look up the property() script command in the help file
I looked it up and I don't have any idea how to use it to solve my case.
I was asking for ready to go script, I could change a little bit of a working script -like the way I did in reversing the timestamp above- but I'm not well-rounded scripting guy to write it on my own.

highend
Posts: 11091
Joined: 06 Feb 2011 00:33

Re: Help with a simple script

Post by highend »

The simplest way (for all timestamps), too lazy to show a way with stored timestamps...

Code: Select all

    setting "BackgroundFileOps", 0;
    foreach($item, <get SelectedItemsPathNames |>, , "e") {
        $parent = <curpath>. "\" . gpc($item, "base");
        moveto $parent, $item, , 2;
        timestamp , $parent . "\" . gpc($item, "file"), $parent;
    }
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Post Reply