Need help writing a renaming script (DDMMYYYY to YYYYMMDD format)
I have a load of photos from my old Nokia phone that I need to rename. A few examples of the current format is "ddmmyyyy.jpg", "ddmmyyyy(001).jpg", "ddmmyyyy(002).jpg" etc, where ddmmyyyy is the date.
I need to rename hundreds of files in a single directory so that the first 8 digits are rearranged into "yyyymmdd.jpg", "yyyymmdd(001).jpg" format etc. Even better if the output format could be "yyyy-mm-dd_(001).jpg" Thanks in advance for any help you can give. :) |
You really want to steer away from having parentheses in your file names. A parenthesis is a special character to the shell. Better use something like "yyyy-mm-dd_001.jpg". That being said, try:
Code:
#!/bin/bash HTH Forrest p.s. You may want to make sure these are backed up first just in case. |
forrest, you don't need the ls
Code:
for file in *.jpg |
Sorry, that was before my second cup of coffee. You're totally right.
Forrest |
Since the file names aren't exactly safe, maybe ls *.jpg | while read file; do..., plus double quotes around "$file". That should be done, anyway, just in case.
Kevin Barry |
I use a regex-rename script (similar to rename found on Slackware) that checks to make sure the number of input files is no greater than the number of output files. For example, your regex might result in two files mapping to the same file, causing the first to be lost.
Code:
#!/bin/sh Code:
useful-rename.sh '^([0-9]{2})([0-9]{2})([0-9]{4})' '\3\2\1' *jpg |
All times are GMT -5. The time now is 10:08 AM. |