Batch rename and datestamp

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
jjk
Posts: 202
Joined: 10 Oct 2007 20:11
Location: Paris

Batch rename and datestamp

Post 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.

highend
Posts: 14639
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Batch rename and datestamp

Post 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^^
One of my scripts helped you out? Please donate via Paypal

jjk
Posts: 202
Joined: 10 Oct 2007 20:11
Location: Paris

Re: Batch rename and datestamp

Post 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 ?

highend
Posts: 14639
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Batch rename and datestamp

Post 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
One of my scripts helped you out? Please donate via Paypal

jjk
Posts: 202
Joined: 10 Oct 2007 20:11
Location: Paris

Re: Batch rename and datestamp

Post 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

highend
Posts: 14639
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Batch rename and datestamp

Post by highend »

And you've written... what? Post it...
I don't understand some parts of that you have written
Which parts?
One of my scripts helped you out? Please donate via Paypal

Post Reply