Skip to content

Instantly share code, notes, and snippets.

@Hexcles
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hexcles/7bdb32025c95292e41cf to your computer and use it in GitHub Desktop.
Save Hexcles/7bdb32025c95292e41cf to your computer and use it in GitHub Desktop.
Rename urlencoded (quoted) filenames
#!/usr/bin/env python3
from sys import argv
from os import path, system
from urllib.parse import unquote
if len(argv) == 1:
print("Usage: urldecode.py FILES...")
exit
for f in argv[1:]:
dn = path.dirname(f)
if dn == '':
dn = '.'
fn = path.basename(f)
fn = path.splitext(fn)
fn = unquote(fn[0]) + fn[1]
cmd = "mv -i '%s' '%s'" % (f, dn + '/' + fn)
print(cmd)
system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment