Skip to content

Instantly share code, notes, and snippets.

@endolith
Last active November 19, 2019 22:11
Show Gist options
  • Save endolith/149676 to your computer and use it in GitHub Desktop.
Save endolith/149676 to your computer and use it in GitHub Desktop.
Convert newlines in filenames to spaces
#!/usr/bin/env python
import os
# I often find myself opening a lot of PDFs, copying and pasting the title of
# the paper, and renaming the file. Often these names have newlines in them,
# though, so this script renames them with spaces instead of newlines.
for name in os.listdir(os.curdir):
if '\n' in name:
new_name = name.replace('\n', ' ')
print(repr(name), '->', repr(new_name))
os.rename(name, new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment