Created
August 12, 2015 00:11
-
-
Save phette23/b6156e3732134358c304 to your computer and use it in GitHub Desktop.
remove leading zeroes Fish script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fish | |
# remove leading zeroes from JPG file names | |
# e.g. page001.jpg => page1.jpg | |
set start (pwd) | |
for dir in (ls) | |
echo "About to rename files in $dir" | |
# optional, makes me less afraid when I step through one folder at a time | |
read | |
# this works around cd-ing into a file; silence error & skip next command(s) | |
cd $dir 2>/dev/null | |
and begin | |
# file extensions could be .jpg, .JPEG, etc. | |
# only need to run twice as our names are like "page001.JPG" | |
rename -v 's/0([0-9])/$1/' *.jp* *.JP* | |
rename -v 's/0([0-9])/$1/' *.jp* *.JP* | |
end | |
# if we're not in the start directory, move back up | |
if [ ! $start = (pwd) ] | |
cd - | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment