Skip to content

Instantly share code, notes, and snippets.

@ariespinoteau
Last active November 13, 2019 10:58
Show Gist options
  • Save ariespinoteau/41cb3565114aed05d5a24898462b89c1 to your computer and use it in GitHub Desktop.
Save ariespinoteau/41cb3565114aed05d5a24898462b89c1 to your computer and use it in GitHub Desktop.
Clean files for windows (remove illegal characters) #shell #ntfs
# 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