Copy dates to matching filenames with Timestamp

Discuss and share scripts and script files...
Post Reply
hermhart
Posts: 213
Joined: 13 Jan 2015 18:41

Copy dates to matching filenames with Timestamp

Post by hermhart »

I have a folder of thousands of files that were converted to another format, but I would like to preserve the dates of the files. I wrote the below code, and it works, but I am wondering if anyone has any suggestions or another way in which to do this that would make it run faster?

Code: Select all

$destination = inputfolder( , "Select Destination Directory of Files to get copied Timestamps");

 foreach($file, listfolder(), "|") {
    $sbase = gpc($file, "base");
    $dfile = quicksearch($sbase, $destination);
    $dbase = gpc($dfile, "base");
    if ("$sbase" == "$dbase") {
       timestamp cma, $file, $dfile;
    }
 }

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

Re: Copy dates to matching filenames with Timestamp

Post by highend »

If not a lot of source files have the exact same date (yyyy-mm-dd hh:mm:ss), no, doing it with XY will need a lot of time, regardless how the normal loop looks like
One of my scripts helped you out? Please donate via Paypal

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

Re: Copy dates to matching filenames with Timestamp

Post by highend »

Here is a fast version...

How to invoke it via XYplorer (adapt the path to the .exe in the script!):

Code: Select all

    $srcFile = "%TEMP%\~XYSourceItems.txt";
    writefile($srcFile, listfolder(, , 1, <crlf>), , "utf8");

    $destination = inputfolder( , "Select Destination Directory of Files to get copied Timestamps");

    $cmd = <<<>>>
"D:\Timestamp\Timestamp_x64.exe" /xyHWnd=<hwnd> /srcFile="$srcFile" /dstPath="$destination" /type="cma"
    >>>;
    run $cmd, "%TEMP%", 2;
The only other thing you should / could change is the /type= parameter
It accepts any combination of "c", "m", "a".
Default is "cma"

It will post a status message to XYplorer when it has finished its job.
E.g. for 2000 files it takes less than 500ms here...
Timestamp_x64_v0.1.zip
(42.45 KiB) Downloaded 138 times
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 213
Joined: 13 Jan 2015 18:41

Re: Copy dates to matching filenames with Timestamp

Post by hermhart »

Thanks, highend!

python80
Posts: 16
Joined: 08 Jul 2022 05:49

Re: Copy dates to matching filenames with Timestamp

Post by python80 »

Hi!

I'm really sorry for bad English.

How can I transfer file timestamps easily Folder1 to Folder2?

Source: X:\TestFolder\Folder1
Target: X:\TestFolder\Folder2

Same files names, same folder structure.
Test-Timestamps
Test-Timestamps
Test.png (41.25 KiB) Viewed 932 times
Thanks for reading.

Post Reply