Created
May 28, 2018 17:56
-
-
Save ailtonbsj/e1d7b278487b264a13bc272713e968c8 to your computer and use it in GitHub Desktop.
Rename files and folders to move from linux to windows cleaning specials characters
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
#!/bin/bash | |
# | |
# HOW TO INSTALL: move to /usr/bin and change permissions to execute | |
if [ "$1" == "--help" ]; then | |
cat << EOF | |
Usage: rename2dos pathfolder counter | |
pathfolder --> Initial folder | |
counter --> Restart counter added in filename | |
Examples: | |
rename2dos ~/documents 0 | |
rename2dos /home/user | |
EOF | |
exit | |
fi | |
cd "$1" | |
if [ "$2" == "0" ]; then | |
echo "0" > /tmp/rename2dos | |
fi | |
for file in *; do | |
if [ -d "$file" ]; then | |
rename2dos "$file" | |
cleaned="${file//[ ()@$:]/_}" | |
croped=${cleaned:0:60} | |
counter="$(cat /tmp/rename2dos)" | |
counter=$((counter+1)) | |
echo $counter > /tmp/rename2dos | |
mv "$file" "$croped$counter" | |
else | |
cleaned="${file//[ ()@$:]/_}" | |
croped=${cleaned:0:60} | |
extension="${cleaned##*.}" | |
counter="$(cat /tmp/rename2dos)" | |
counter=$((counter+1)) | |
echo $counter > /tmp/rename2dos | |
mv "$file" "$croped$counter.$extension" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment