Skip to content

Instantly share code, notes, and snippets.

@glasslion
Created October 15, 2019 07:32
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 glasslion/5a41b47baead4ef2266465908920fab8 to your computer and use it in GitHub Desktop.
Save glasslion/5a41b47baead4ef2266465908920fab8 to your computer and use it in GitHub Desktop.
修复 Linux 下载的 urlencode 过的文件名
# -*- coding: utf-8 -*-
import glob
import os
import urllib
def confirm(text):
answer = raw_input(text)
answer = answer.lower()
return answer == 'y' or answer == 'yes'
def main():
dir_path = raw_input(
"Please enter the directory path [~/Downloads ]:")
dir_path = dir_path or '~/Downloads/'
dir_path = os.path.expanduser(dir_path)
os.chdir(dir_path)
files = glob.glob('%E*')
for file in files:
decoded = urllib.unquote_plus(file)
if confirm("Do you want to rename {} to {}? [yes|no]".format(file, decoded)):
os.rename(file, decoded)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment