2
1
I am using Windows, and trying to use Cygwin to perform this task. I would like to rename the files and directories recursively as following:
From:
1010110010\
1010110010\1010110010.jpg
1010110010\1010110010.txt
1010110020\
1010110020\1010110020.jpg
1010110020\1010110020.txt
...
to:
1-01-01-1-001-0\
1-01-01-1-001-0\1-01-01-1-001-0.jpg
1-01-01-1-001-0\1-01-01-1-001-0.txt
1-01-01-1-002-0\
1-01-01-1-002-0\1-01-01-1-002-0.jpg
1-01-01-1-002-0\1-01-01-1-002-0.txt
...
I was thinking about using for loop, but for loop could not traverse the directories recursively. I can only use for and sed to rename a list of files in a directory:
for i in *; do j=`echo $i | sed 's/\(.\)\(..\)\(..\)\(.\)\(...\)\(.\)/\1-\2-\3-\4-\5-\6/g'`; mv $i $j; done
But I would like to rename several directories and the files within. So, I tried about "find", but I don't know how to use variables and regular expression with "find" command. Besides that, since I am using Cygwin, I can only use "mv" command instead of "rename" command. Thanks for any suggestions.
rename(1)
does not work the same as in Windows. Its syntax isrename PATTERN REPLACEMENT [files...]
. – amphetamachine – 2010-09-04T13:54:27.573But the rename command is not found in Cygwin. So, I would like to use "mv" to rename the file. – Allen – 2010-09-04T13:57:14.987