Last active
July 28, 2016 06:11
-
-
Save futurulus/c0d5466d1f0411ad4f8bb5f7517ac82b to your computer and use it in GitHub Desktop.
Ever get impossible-to-delete files on Windows because they have * or ? in their names?
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 bash | |
# Rename files in a Windows folder that somehow ended up with illegal Windows filenames | |
# (because NTFS doesn't enforce this, but it makes the files unusable and indestructible). | |
# Must be run in Linux. There seems to be no other way. | |
ls -1 | awk '/[/\:*?"<>|]/ { | |
orig = $0; | |
gsub(/[/\:*?"<>|]/, "_", $0); | |
gsub(/'"'"'/, "'"'"'\"'"'"'\"'"'"'", orig); | |
gsub(/'"'"'/, "'"'"'\"'"'"'\"'"'"'", $0); | |
print "mv '"'"'" orig "'"'"' '"'"'" $0 "'"'"'" | |
}' | bash -s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment