Page 1 of 1
Help with a simple script
Posted: 20 Oct 2018 00:03
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;
}
Re: Help with a simple script
Posted: 20 Oct 2018 03:39
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()
Re: Help with a simple script
Posted: 20 Oct 2018 08:56
by karimmaster101
Sorry for this mistake, I edited the post.
Re: Help with a simple script
Posted: 21 Oct 2018 05:48
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?
Re: Help with a simple script
Posted: 21 Oct 2018 05:56
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;
}
Re: Help with a simple script
Posted: 21 Oct 2018 06:02
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?
Re: Help with a simple script
Posted: 21 Oct 2018 06:06
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.
Re: Help with a simple script
Posted: 21 Oct 2018 11:41
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
Re: Help with a simple script
Posted: 25 Oct 2021 01:05
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
Re: Help with a simple script
Posted: 25 Oct 2021 04:03
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.
Re: Help with a simple script
Posted: 25 Oct 2021 10:23
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
Re: Help with a simple script
Posted: 25 Oct 2021 10:27
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
Re: Help with a simple script
Posted: 25 Oct 2021 11:08
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.
Re: Help with a simple script
Posted: 25 Oct 2021 11:30
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;
}