Renaming or swapping I can't figure it out, need help
Hi everyone.
I'm trying to rename some 1400 files and have trouble getting it right. I'm trying to swap the year which is at the end of the filename to the beginning of the filename
I want to change from
China 20 Yuan 2025
China 20 Yuan 2025_
Eastern Caribbean 2 Dollars 2024
Eastern Caribbean 2 Dollars 2024_
Isle of Man 1 Pound 1983
Isle of Man 1 Pound 1983_
to
2025 China 20 Yuan
2025_ China 20 Yuan
2024 Caribbean 2 Dollars
2024_ Eastern Caribbean 2 Dollars
1983 Isle of Man 1 Pound
1983_ Isle of Man 1 Pound
Is there a pattern or script that can accomplish this? I'm using the latest version 4.16.1.
Please help.
Thank you.
I'm trying to rename some 1400 files and have trouble getting it right. I'm trying to swap the year which is at the end of the filename to the beginning of the filename
I want to change from
China 20 Yuan 2025
China 20 Yuan 2025_
Eastern Caribbean 2 Dollars 2024
Eastern Caribbean 2 Dollars 2024_
Isle of Man 1 Pound 1983
Isle of Man 1 Pound 1983_
to
2025 China 20 Yuan
2025_ China 20 Yuan
2024 Caribbean 2 Dollars
2024_ Eastern Caribbean 2 Dollars
1983 Isle of Man 1 Pound
1983_ Isle of Man 1 Pound
Is there a pattern or script that can accomplish this? I'm using the latest version 4.16.1.
Please help.
Thank you.
Reply to #1:
Hi Gerson,
You need to use the Replace method with regular expressions.
Replace: (.*) (\d{4}_|\d{4})
Replace with: \2 \1
Use regular expressions: checked
See the following image:
https://i.postimg.cc/66cZdGFx/Img-003.png
This way, you have separated the two parts of the filename: the first part (.*), which is the part of the filename up to the year, and the second part, which is the year (four digits), with or without the underscore.
In the 'Replace with' field, these portions of the filename have been swapped.
I hope this helps you
Hi Gerson,
You need to use the Replace method with regular expressions.
Replace: (.*) (\d{4}_|\d{4})
Replace with: \2 \1
Use regular expressions: checked
See the following image:
https://i.postimg.cc/66cZdGFx/Img-003.png
This way, you have separated the two parts of the filename: the first part (.*), which is the part of the filename up to the year, and the second part, which is the year (four digits), with or without the underscore.
In the 'Replace with' field, these portions of the filename have been swapped.
I hope this helps you
Reply to #2:
Thank you Styb, that did the trick. One more thing, if I want to move the year
1983 Isle of Man 1 Pound
to
Isle of Man 1983 1 Pound
How can the variable you provided be tweaked?
I appreciate your help.
Thanks again.
Gerson
Thank you Styb, that did the trick. One more thing, if I want to move the year
1983 Isle of Man 1 Pound
to
Isle of Man 1983 1 Pound
How can the variable you provided be tweaked?
I appreciate your help.
Thanks again.
Gerson
Reply to #3:
So, in a similar way, you can divide the file name into four portions: the first is formed by words, the second by the coin value (one or more digits), the third by words, and the fourth by the year, with or without the underscore. You can reorder these sections as you wish. For example:
Replace: (.*) (\d+) (.*) (\d{4}_|\d{4})
Replace with: \1 \4 \2 \3
Use regular expressions: checked
See the following image:
https://i.postimg.cc/C1TrgcqW/Img-009.png
There may be a better way to do this, but for now I hope this is sufficient, and you will need to wait for more experienced users. :D
So, in a similar way, you can divide the file name into four portions: the first is formed by words, the second by the coin value (one or more digits), the third by words, and the fourth by the year, with or without the underscore. You can reorder these sections as you wish. For example:
Replace: (.*) (\d+) (.*) (\d{4}_|\d{4})
Replace with: \1 \4 \2 \3
Use regular expressions: checked
See the following image:
https://i.postimg.cc/C1TrgcqW/Img-009.png
There may be a better way to do this, but for now I hope this is sufficient, and you will need to wait for more experienced users. :D
Reply to #4:
Thank you Styb. Your script code worked for 99% of the files, it renamed them properly. There is an issue that it run into when it comes to fractional amounts in my scenario for example
Tunisia 0.5 Dinar 1973
Your code didn't execute the change (see screenshot) https://postimg.cc/6ywFNqcS
Hopefully you can assist with this minor detail.
Thanks again.
Gerson
Thank you Styb. Your script code worked for 99% of the files, it renamed them properly. There is an issue that it run into when it comes to fractional amounts in my scenario for example
Tunisia 0.5 Dinar 1973
Your code didn't execute the change (see screenshot) https://postimg.cc/6ywFNqcS
Hopefully you can assist with this minor detail.
Thanks again.
Gerson
Reply to #5:
Hi Gerson,
Styb's probably not available (it's late over there) but here's all you need to do (if Styb's second solution is more like what you want, anyway... I'm a little confused):
Where Styb wrote the "Replace: " string as:
(.*) (\d+) (.*) (\d{4}_|\d{4})
just use:
(.*) ([\d\.]+) (.*) (\d{4}_|\d{4})
instead (just a small change within the second parenthesis pair). Instead of just looking for numbers it also now looks for the period/decimal point. No need to change anything else.
https://drive.google.com/file/d/1zoH35R7IiQvgfFfCuNISc64AGwA I1KXA/view?usp=sharing
Hope that helps until Styb gets back. :)
Best,
DF
Hi Gerson,
Styb's probably not available (it's late over there) but here's all you need to do (if Styb's second solution is more like what you want, anyway... I'm a little confused):
Where Styb wrote the "Replace: " string as:
(.*) (\d+) (.*) (\d{4}_|\d{4})
just use:
(.*) ([\d\.]+) (.*) (\d{4}_|\d{4})
instead (just a small change within the second parenthesis pair). Instead of just looking for numbers it also now looks for the period/decimal point. No need to change anything else.
https://drive.google.com/file/d/1zoH35R7IiQvgfFfCuNISc64AGwA I1KXA/view?usp=sharing
Hope that helps until Styb gets back. :)
Best,
DF
Reply to #6:
Thanks, DF. Your code worked!
If I may, I would like to ask for another switch of renaming. How to replace the following:
China 2025_ 20 Yuan
To
China 2025 20_ Yuan
I want to move the underscore character to another area. Any advice and input will be appreciated.
Regards.
Gerson
Thanks, DF. Your code worked!
If I may, I would like to ask for another switch of renaming. How to replace the following:
China 2025_ 20 Yuan
To
China 2025 20_ Yuan
I want to move the underscore character to another area. Any advice and input will be appreciated.
Regards.
Gerson
Reply to #7:
Hi guys, I'm back! :D
Try this in a similar way:
Replace: (.*) (\d+)_ ([\d\.]+) (.*)
Replace with: \1 \2 \3_\4
Regular expressions: checked
I have removed the space between the coin value and its name, but you can reinsert it if you wish, ie
\1 \2 \3_ \4
@DF
Thank you. You reminded me of the use of square brackets. :)
The (\d{4}_|\d{4}) can be converted into the plus simple ([\d\_]+)
Best
Hi guys, I'm back! :D
Try this in a similar way:
Replace: (.*) (\d+)_ ([\d\.]+) (.*)
Replace with: \1 \2 \3_\4
Regular expressions: checked
I have removed the space between the coin value and its name, but you can reinsert it if you wish, ie
\1 \2 \3_ \4
@DF
Thank you. You reminded me of the use of square brackets. :)
The (\d{4}_|\d{4}) can be converted into the plus simple ([\d\_]+)
Best
Reply to #8:
Well hi there, Mr. Styb! Good to "see" you my friend!
You're welcome, but there's almost always several ways to do something in regex. Character classes are one great way, of course, but alternation in a saved reference is not only useful but, I think, sometimes more efficient. And either way can get the job done here! :)
Gerson, if you want to make that one small change to a small subset of files, this alternative *might* cause less disruption to already-reconfigured filenames:
Replace: "_ ([\d\.]+) "
With: " $1_ "
Regex on.
[Leave out the quote marks; they are only to demonstrate the spaces in the regex]
Remember, watch the preview column and don't forget undo batch.
(B(est( regards)?|e safe|ye( bye)?( for now)?)) :))
DF
(OMG, I just grossed *myself* out! Must be a back-reference! Crap, I can't stop!)
Well hi there, Mr. Styb! Good to "see" you my friend!
You're welcome, but there's almost always several ways to do something in regex. Character classes are one great way, of course, but alternation in a saved reference is not only useful but, I think, sometimes more efficient. And either way can get the job done here! :)
Gerson, if you want to make that one small change to a small subset of files, this alternative *might* cause less disruption to already-reconfigured filenames:
Replace: "_ ([\d\.]+) "
With: " $1_ "
Regex on.
[Leave out the quote marks; they are only to demonstrate the spaces in the regex]
Remember, watch the preview column and don't forget undo batch.
(B(est( regards)?|e safe|ye( bye)?( for now)?)) :))
DF
(OMG, I just grossed *myself* out! Must be a back-reference! Crap, I can't stop!)
Reply to #9:
Thank you, DF and Styb for your great help!
If I may ask you for one last favor.
The following codes that you provided did the work that I wanted for renaming my many files
(.*) ([\d\.]+) (.*) (\d{4}_|\d{4})
\1 \4 \2 \3
and
_ ([\d\.]+)
$1_
Now if I want to place the underscore at the end of the filename, what do I change to? For any file that has underscore anywhere within the beginning or end of a word, I would like to move it to the end of the filename.
from
Estonia 1992 1_ Kroon
Fiji 1980 1_ Dollar
to
Estonia 1992 1 Kroon_
Fiji 1980 1 Dollar_
Your help is greatly appreciated.
Regards,
Gerson
Thank you, DF and Styb for your great help!
If I may ask you for one last favor.
The following codes that you provided did the work that I wanted for renaming my many files
(.*) ([\d\.]+) (.*) (\d{4}_|\d{4})
\1 \4 \2 \3
and
_ ([\d\.]+)
$1_
Now if I want to place the underscore at the end of the filename, what do I change to? For any file that has underscore anywhere within the beginning or end of a word, I would like to move it to the end of the filename.
from
Estonia 1992 1_ Kroon
Fiji 1980 1_ Dollar
to
Estonia 1992 1 Kroon_
Fiji 1980 1 Dollar_
Your help is greatly appreciated.
Regards,
Gerson
Reply to #10:
Regular expressions are an incredibly useful tool, but in some cases a basic 'Replace' method combined with an 'Add' method is enough.
Replace method:
Replace: _
Replace with: (nothing)
Replacing the underscore with "nothing" will result in a file name without the underscore. The 'Add' method should now be included in the list of methods in order to include the underscore at the end of the file name.
Add: _
At index: 0
Backwards: checked
Apply to name
Ciao!
Regular expressions are an incredibly useful tool, but in some cases a basic 'Replace' method combined with an 'Add' method is enough.
Replace method:
Replace: _
Replace with: (nothing)
Replacing the underscore with "nothing" will result in a file name without the underscore. The 'Add' method should now be included in the list of methods in order to include the underscore at the end of the file name.
Add: _
At index: 0
Backwards: checked
Apply to name
Ciao!
Reply to #11:
Gents,
Sorry to contradict ya Styb, but I think some of the files don't have underscores. Gerson, if you don't want all files to have them you could use one replace like this:
Replace: "_(.+)$"
With: " $1_"
Regex on (and leave the quote marks out, they are to show that you'll need a space at the start of the With: part).
That way, files without underscores wouldn't get them added.
You are telling the program to look for an underscore followed by some characters. Store the remaining characters in $1. Remove the underscore, replace the rest with a space (so the words surrounding the underscore won't run together) followed by what's in $1, and then the underscore at the end. "(.+)" is needed instead of "(.*)" so that if the underscore is already at the end of the filename the program won't just add a space in front of it.
Best,
DF
Gents,
Sorry to contradict ya Styb, but I think some of the files don't have underscores. Gerson, if you don't want all files to have them you could use one replace like this:
Replace: "_(.+)$"
With: " $1_"
Regex on (and leave the quote marks out, they are to show that you'll need a space at the start of the With: part).
That way, files without underscores wouldn't get them added.
You are telling the program to look for an underscore followed by some characters. Store the remaining characters in $1. Remove the underscore, replace the rest with a space (so the words surrounding the underscore won't run together) followed by what's in $1, and then the underscore at the end. "(.+)" is needed instead of "(.*)" so that if the underscore is already at the end of the filename the program won't just add a space in front of it.
Best,
DF
Reply to #12:
Hi DF,
No problem if you contradict me. Your solution is brilliant!
@Gerson: I need to correct my previous answer by adding a condition: apply the Add method only if the original name contains an underscore.
See the picture below:
https://postimg.cc/Xp4mLzTy
Have a good day!
Hi DF,
No problem if you contradict me. Your solution is brilliant!
@Gerson: I need to correct my previous answer by adding a condition: apply the Add method only if the original name contains an underscore.
See the picture below:
https://postimg.cc/Xp4mLzTy
Have a good day!
Reply to #13:
Thank you DF and Styb. The last code from DF did the trick. I renamed all of my files and didn't have a hiccup. Amazing knowledge you both have and above all you give amazing help.
Be blessed and have a great day.
Regards,
Gerson
Thank you DF and Styb. The last code from DF did the trick. I renamed all of my files and didn't have a hiccup. Amazing knowledge you both have and above all you give amazing help.
Be blessed and have a great day.
Regards,
Gerson