使用 Python 批处理文件重命名

Batch File Rename with Python

下面是我在给定目录中批量重命名图片的代码

def multi_filename_change():
i = 0
files = askstring('Select your folder', 'Paste your directory path where your images are stored.')
for file in os.listdir(files):
    if not file.startswith('.'):
        file_name = askstring('Add file name', 'Please enter a name for your files.')
        src = file
        dst = file_name + str(i) + ".jpg"
        os.rename(src, dst)
        i += 1

当这是 运行 时,我收到以下错误消息:

os.rename(src, dst) FileNotFoundError: [Errno 2] No such file or directory: '360007_space-wallpaper-4k.jpg' -> 'test0.jpg'

我似乎无法解决这个问题,这对你们这些专家来说可能很简单:)

谢谢

源应该附加现有目录,而不仅仅是文件名

src=文件+文件

或者
src=os.path.join(文件,文件)