首页 > 解决方案 > os.rename 移动文件,然后在 2 秒后撤消 - Google Drive?

问题描述

如果我在普通目录中运行它,它将起作用。使用 shutil.move 具有相同的结果。

    from os import listdir, rename
    from os.path import getmtime, isfile

    for x in match_list:
        file_location = f'{f}\\{x[0]}'
        file_destination = f'{f}{old_dir}\\{x[0]}'
        if isfile(file_location):
            if isfile(file_destination):
            dot_loc = file_destination.rfind('.')
            file_destination = f'{file_destination[:dot_loc]}(1)', f'{file_destination[dot_loc:]}'
            rename(file_location, file_destination)
        else:
            rename(file_location, file_destination)

标签: pythonrenamemovedrivegdrive

解决方案


推荐阅读