Python版RenameURLCode
来源:互联网 发布:mac怎么进qq游戏大厅 编辑:程序博客网 时间:2024/06/07 07:25
学习了几天Python之后,为了巩固所学知识,使用Python写了一个转换URL字符文件的脚本,之前用JavaScript写过一个放在SAE上(RenameURLCode),但一直希望有一个客户端的工具。
# coding:utf-8import osimport reneedToTransform = FalsepathName = raw_input('Enter a directory name: ')extName = raw_input('file extension: ')fileList = os.listdir(pathName)reg = r'.*\.'+extNameencodedURL = ['%5B', '%5D']decodedURL = ['[', ']']#REVERSE# encodedURL = ['[', ']']# decodedURL = ['%5B', '%5D']finalFileName = []originFileName = []for fileName in fileList:#列出指定目录下所有文件if re.match(reg, fileName, re.I):#列出所有PDF文件for encodeIndex in encodedURL:#循环判断单个PDF文件名是否包含URL字符if(fileName.find(encodeIndex) != -1):#列出所有包含URL字符的PDF文件originFileName.append(fileName)chIndex = 0for encodeStrIndex in encodedURL:fileName = fileName.replace(encodeStrIndex, decodedURL[chIndex])chIndex+=1finalFileName.append(fileName)breakif len(originFileName) > 0:needToTransform = Trueprint unicode('\n\t原始文件名:', 'utf8')for i in originFileName:print iprint '\n'+'='*100+'\n'print unicode('\t转换文件名:', 'utf8')for i in finalFileName:print ielse:print unicode('没有文件需要转换!', 'utf8')while needToTransform:print '\n'confirm = raw_input('Sure to change file names as below? (Y/N): ')if(confirm == 'y' or confirm == 'Y'):fileIndex = 0for originFileIndex in originFileName:os.rename(pathName+'\\'+originFileIndex, pathName+'\\'+finalFileName[fileIndex])fileIndex+=1breakelif(confirm == 'n' or confirm == 'N'):breakURLDecoder.py
0 0
- Python版RenameURLCode
- OCR识别python版及python代码
- suffix tree,python 版
- viterbi算法 python版
- 8皇后 python版
- Python版html_entity_decode(text):
- Python版DNW
- Python 3.3版发布
- Bloom Filter(python版)
- XXTEA Python版代码
- Python 爪巴虫 2.0版
- python版爬虫
- Python俄罗斯方块改进版
- python版文件批量改名
- Python版 HelloWorld
- Python 3.3版发布
- ping 源代码,python版
- Python 3.3版发布
- UI022---xib自定义UITableView
- B\S备忘录25——集群初识
- 电脑自带键盘和模拟器键盘互相切换
- iOS入门(十一)结构体指针
- 键值编码 || Cocoa绑定
- Python版RenameURLCode
- Java中的哈希表Hashtable
- Spring学习笔记四(AOP中的通知参数和注解开发)
- hdu5349__MZL's simple problem
- hdu 2553 N皇后问题
- java并发包中的Condition和Lock 取代Synchronized、wait、notify/notifyAll实现线程的同步与互斥
- 正则表达使用小栗子
- 集成ACEGI 进行权限控制
- Activity 学习