Skip to content

Instantly share code, notes, and snippets.

@landge
Created March 9, 2020 14:49
Show Gist options
  • Save landge/76b2d2d219a5ebd074647ba57ca09364 to your computer and use it in GitHub Desktop.
Save landge/76b2d2d219a5ebd074647ba57ca09364 to your computer and use it in GitHub Desktop.
Rename files in current and subdirectories!
import pathlib
def main():
path = pathlib.Path.cwd()
for i in path.glob('**/*'):
if ' ' in i.name:
print(i,i.name)
new_name = i.parent / i.name.replace(' ','_')
i.rename(new_name)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment