通过python批量重命名后丢失文件(os.rename)

时间:2018-12-25 06:46:36

标签: python python-3.x batch-rename renaming

我写了一个Python脚本来重命名特定文件夹中存在的所有JPG和jpeg文件。

我将目录更改为包含所有jpg,JPG文件和named.py(这是我编写的脚本)的文件夹。

import os
cwd=os.getcwd()
for file in os.listdir(cwd):
    i=1
    if file.endswith('.JPG') or file.endswith('.jpeg'):
        new=str(i)+'.JPG'
        os.rename(file, new)
        i+=1

运行脚本后,所有JPG和jpeg文件都丢失了。(编辑:1.JPG除外)
为什么会发生这种情况以及如何恢复文件?

0 个答案:

没有答案
相关问题