【发布时间】:2022-10-25 23:41:07
【问题描述】:
我想将所有文件从多个子目录移动到与父文件夹位于同一目录中的另一个文件夹,但出现以下错误:
FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Dev/FaceRec/lfw/Emmit_Smith/Emmit_Smith_0001.jpg' -> '/content/drive/MyDrive/Dev/FaceRec/negatives/Emmit_Smith_0001.jpg'
这是我的代码:
for directory in os.listdir('/content/drive/MyDrive/Dev/FaceRec/lfw'):
for file in os.listdir(os.path.join('/content/drive/MyDrive/Dev/FaceRec/lfw', directory)):
path = os.path.join('/content/drive/MyDrive/Dev/FaceRec/lfw', directory, file)
new_path = os.path.join('/content/drive/MyDrive/Dev/FaceRec/negatives', file)
os.replace(path, new_path)
提前感谢您的帮助
【问题讨论】:
-
/content/drive/MyDrive/Dev/FaceRec/lfw/Emmit_Smith/Emmit_Smith_0001.jpg 是链接吗?
-
是的,它是其中一个子文件夹中的文件(抱歉花了一段时间才找到它)
-
目录
/content/drive/MyDrive/Dev/FaceRec/negatives是否存在? -
@Cuartero 是的,它存在于其中,它们都位于 FaceRec
标签: python