python批量修改文件名称,同时将文件写入txt文件
2018-02-01 21:19
441 查看
//批量修改文件名称 import os dir = os.getcwd() dir = os.chdir(r'C:\Users\Administrator\Desktop\cupdata') j = 0 for file in os.listdir(dir): #os.listdir('.')遍历文件夹内的每个文件名,并返回一个包含文件名的list if file[-2: ] == 'py': continue #过滤掉改名的.py文件 os.rename(file,str(j)+'.jpg') j+=1 print (file) # print (dir) # # dir = "c:\windows" # # if os.path.exists(dir): # # print("Hello World") # # else : # # print("Hello World1")
//修改文件名称的同时将文件名称写入txt文件中 import os dir = os.getcwd() dir = os.chdir(r'C:\Users\Administrator\Desktop\img') f = open(r'C:\Users\Administrator\Desktop\bg.txt','a') j = 0 for file in os.listdir(dir): #os.listdir('.')遍历文件夹内的每个文件名,并返回一个包含文件名的list if file[-2: ] == 'py': continue #过滤掉改名的.py文件 os.rename(file,'bg'+str(j)+'.jpg') f.write('img/bg'+str(j)+'.jpg' + '\n') j+=1 print (file)
相关文章推荐
- python批量修改文件名称
- 20130317 如何批量把文件名称写入txt文档
- P-1.7 [有例题]Python读取、写入.txt文件
- Python 如何将中文变量写入txt文件
- 批量修改文件名称的方法
- 在ArcGIS中,用Python脚本批量修改FeatureClass的名称与字段
- linux下批量修改目录下所有文件夹、文件名称及文件内容
- python批量修改文件
- python修改txt文件内容
- hivepython 同时读入python 且python脚本中处理外部文件txt
- 配置FatFs并批量写入txt文件
- Python修改Mp3文件名称
- python文件操作之批量修改文件后缀名的方法
- python读取TXT文件并逐行写入另外一个TXT文件
- Python 多线程搜索txt文件的内容,并写入搜到的内容(Lock)
- Python每日练习 14 15 16 将某txt的内容写入到xls文件中
- python3将csv文件中的两列数据读取出来,并且按行写入txt文本之中
- python 修改文件名和提取文件到txt
- python批量读取txt文件为DataFrame
- 在windows cgywinportable上,通过执行linux命令,批量修改文件名称。