File name to file date

Bulk Rename Utility How-To's

File name to file date

Postby DerSteel » Fri Jul 24, 2020 12:53 pm

Hello,

is there a way to set the file created and file modified date based on the file name?

For example, I have a file named "Filename - Filenumber - 2020.01.24_23.07.31.65.xyz" and I want the file date (created and modified) to 24.01.2020, 23.07 and 31 seconds. The 65 is milliseconds and of can/should be ignored.

I bet that's complicated so I could live with at least the date to 24.01.2020 and the clock set to a fixed 23.59.

The background is, I have about 700 small files of a surveylance cam. For some strange reasons they all have a weird width dimension and need to be cropped. Ofc after editing they would all have to wrong file dates. So I need to edit (crop) them and change their files dates back to the original one after editing.


Sorry for my bad english. I hope you can understand my request.
Thanks in advance.
DerSteel
 
Posts: 2
Joined: Tue Jul 21, 2020 12:27 am

Re: File name to file date

Postby therube » Sun Jul 26, 2020 1:07 pm

pseudo-code...

work on backup sets of your cam files

original files; c:/cam/
working set; c:/cam/x/

make your edits to the files in c:/cam/x/

after making your edits
use Unix touch command to set the file date time from the source in /cam/ to the edited file in /cam/x/
Code: Select all
touch.exe -c  -r  %1  x\%1

you would wrap that in a for loop
such that for every file in /cam/ it would "touch" the associated edited file date in /cam/x/ back to its original date (the date as it is in the source files, /cam/)

---

touch.exe can be found in, coreutils-5.3.0-bin.zip.
Copy touch.exe out from there, & place it somewhere in your path (or point to its location in your batch file such that it can be found).

---

(I'm not too good with batch files, but) maybe something like this will work?

set_edit_to_source_date.bat:
Code: Select all
for %%i in (*)  do touch.exe -c  -r %%i   x\%%i

You would run that batch file from within the c:/cam/ directory.
therube
 
Posts: 1319
Joined: Mon Jan 18, 2016 6:23 pm

Re: File name to file date

Postby DerSteel » Sun Jul 26, 2020 6:12 pm

Thank you very much for your answer. I will try it as soon I can.
DerSteel
 
Posts: 2
Joined: Tue Jul 21, 2020 12:27 am


Return to How-To