I am running this script in cygwin, but since I found the original
here, I figured it would be OK to post here.
I'm using this to extract the contents of a version control system folder dump into something usable. It was previously gziped up (eg 1.1.gz) but that's been fixed.
The way my modified script works now, it runs through all subdirectories and properly renames files with names like "1.1" and changes them to be foldername.ext, which is perfect. It also has the bonus of overwriting a 1.1 file with a 1.2 file (which happens to be a newer version) which is also the behavior I want.
W
hat isn't perfect is when it does something I don't want, like this:
mv PATH\fileone.ext PATH.ext
fileone.ext will NEVER start with "1" and I'd like to stop the script from performing any commands on a file that begins with "1"
Here's the directory structure
Code:
C:\PATH
C:\PATH\fileone.ext
C:\PATH\filetwo.ext
C:\PATH\filethree.ext
C:\PATH\folder1,d\
-----------------\1.1
-----------------\1.2
C:\PATH\folder2,d\
-----------------\1.1
-----------------\1.2
-----------------\1.3
C:\PATH\folder3,d\
-----------------\1.1
-----------------\1.2
-----------------\1.3
C:\PATH\folder4,d\subdirectory1\
------------------------------\filefour.ext
------------------------------\filefive.ext
------------------------------\filesix.ext
C:\PATH\folder5,d\subdirectory2,d\
------------------------------\1.1
------------------------------\1.2
------------------------------\1.3
Code:
#!/bin/bash
while read file
do
basename=${file##*/}
if [ $(expr index "$basename" .) -gt 0 ]
then
extension=.${file##*.}
else
extension=""
fi
dirname=${file%/*}
newname=${dirname##*/}
newname=`echo "$newname$extension" | cut -d',' -f1`
echo mv "$file" "$dirname/$newname"
done < <(find FOLDERPATH -type f)
-Wayne