Page 1 of 1
Copy dates to matching filenames with Timestamp
Posted: 07 Feb 2021 00:24
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;
}
}
Re: Copy dates to matching filenames with Timestamp
Posted: 07 Feb 2021 00:39
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
Re: Copy dates to matching filenames with Timestamp
Posted: 07 Feb 2021 12:09
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...
Re: Copy dates to matching filenames with Timestamp
Posted: 07 Feb 2021 18:45
by hermhart
Thanks, highend!
Re: Copy dates to matching filenames with Timestamp
Posted: 09 Jul 2022 17:35
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.png (41.25 KiB) Viewed 980 times
Thanks for reading.