Created
October 15, 2019 07:32
-
-
Save glasslion/5a41b47baead4ef2266465908920fab8 to your computer and use it in GitHub Desktop.
修复 Linux 下载的 urlencode 过的文件名
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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