Last active
November 13, 2019 10:58
-
-
Save ariespinoteau/41cb3565114aed05d5a24898462b89c1 to your computer and use it in GitHub Desktop.
Clean files for windows (remove illegal characters) #shell #ntfs
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
# Remove illegal character for windows files | |
# <>:"/\|?* | |
# | |
# / is being ignored as it is tricky to rename this character | |
# | |
# -E option is added to sed command in order to work on OSX | |
# | |
# First rename files | |
find . -type f -d -name '*[<>:\\\|?\*\"]*' -exec bash -c 'x="{}"; y="$(sed -E "s/[<>:\\\|?\*\"]+/-/g" <<< "$x")" && mv "$x" "$y" && echo "change $x to $y" ' \; | |
# Then rename folders | |
find . -type d -d -name '*[<>:\\\|?\*\"]*' -exec bash -c 'x="{}"; y="$(sed -E "s/[<>:\\\|?\*\"]+/-/g" <<< "$x")" && mv "$x" "$y" && echo "change $x to $y" ' \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment