Skip to content

Instantly share code, notes, and snippets.

@villeodell
Last active October 26, 2022 10:53
Show Gist options
  • Save villeodell/9a6d69888910128c35305b3276f168a2 to your computer and use it in GitHub Desktop.
Save villeodell/9a6d69888910128c35305b3276f168a2 to your computer and use it in GitHub Desktop.
Clean filenames for OneDrive or FAT32
#!/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