Last active
October 26, 2022 10:53
-
-
Save villeodell/9a6d69888910128c35305b3276f168a2 to your computer and use it in GitHub Desktop.
Clean filenames for OneDrive or FAT32
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/zsh | |
#------------------------------------------------------------------ | |
# Strip illegal characters :;*?\"<>| recursively beginning in | |
# the directory it is run from. | |
# | |
# Use when preparing to sync or copy files to a filesystem | |
# that does not allow these characters. (MS OneDrive, fat32, etc..) | |
# | |
# zmv [OPTIONS] oldpattern newpattern | |
# -n No execution: print what would happen, but don’t do it. | |
# Q and D flags are used to include hidden files | |
# | |
# Credit: | |
# https://manpages.ubuntu.com/manpages/bionic/man1/zsh-lovers.1.html | |
#------------------------------------------------------------------- | |
autoload zmv | |
unwanted='[:;*?\"<>|]' | |
zmv -n -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment