Page 1 of 1
Batch rename and datestamp
Posted: 19 Dec 2019 17:02
by jjk
Hello all
I have some files :
Science et Vie june 2019.pdf
Science et Vie july 2019.pdf
Science et Vie september 2019.pdf
...
I would to rename them, in one shot, as :
S&V 201906.pdf
S&V 201907.pdf
S&V 201909.pdf
...
More, if possible, datestamp them (last modified date) as :
01/06/2019 00:00
01/07/2019 00:00
01/09/2019 00:00
...
Is it possible by one shot (or one shot for renaming, and one shot more for datestamping), if needed, by script ?
And, finally, can I save the whole procedure to be able to reapply it to some other files groups ?
Thanks in advance to all who can help me.
Re: Batch rename and datestamp
Posted: 19 Dec 2019 17:14
by highend
1. Sure, scripting is the way to go here
Reapplying it to other group of files? Depends on if the pattern is the same (<description> <english month> <yyyy year>)
2. You mean timestamp them while the english month + yyyy year are the source for the date used?
And the first of the month + 00:00:00 are the defaults?
If 2 * true: Sure, this can be scripted as well
Both scripts need a regex pattern (or the clumsy way: gettoken while the month is the separator -> 12 checks in the loop)...
And of course it's possible to bake both functions into the same script^^
Re: Batch rename and datestamp
Posted: 19 Dec 2019 20:45
by jjk
Thanks highend
But unfortunately I am unble to write a such script.
For your Point 2, yes, you have understood my request.
Anyway, is there anyone to write at least some explanations for begin that script ?
Re: Batch rename and datestamp
Posted: 19 Dec 2019 21:30
by highend
1. Get selected files
2. Put all english month names (separated by |) in a $months variable
3. Loop over all selected files
4. Capture all parts via this regex and use gettoken to break them up into the description, the month, year and extension
$parts = regexreplace($file, "^(.+?)\s+($months)\s+(\d{4})(\.[^.]+)$", "$1|$2|$3|$4");
5. Rebuild the new name from these parts (to get the month as digits, use gettokenindex() on the $months variable)
6. Rebuild the new date
7. timestamp + rename
Re: Batch rename and datestamp
Posted: 21 Dec 2019 17:37
by jjk
Thank you highend.
I tried to write the script, but unfortunately I am unable to make it to work.
And also I don't understand some parts of that you have written, and above all to translate them to working code.
I'm just able to adapt a working code (ie adjusting to my exact needs)
Anyway, thanks highend
Re: Batch rename and datestamp
Posted: 21 Dec 2019 17:44
by highend
And you've written... what? Post it...
I don't understand some parts of that you have written
Which parts?