我在这里有一个python脚本,可以多次复制图像,第一次复制图像是成功的,但第二次复制了这个错误。我肯定知道我把我的目录改成了一个级别,或者我做错了吗?任何想法?
os.chdir(path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'my_images/babesia divergen
这是我的代码
import os
import shutil
for file in os.listdir("my_images/"):
path='my_images/' + file
os.chdir(path)
cwd=os.getcwd()
print(cwd)
images=os.listdir(cwd)
a = 0
while a < 2:
a = a + 1
shutil.copy2(images[0],os.path.splitext(images[0])[0]+str(a)+os.path.splitext(images[0])[1])
print(os.path.splitext(images[0])[0],a,os.path.splitext(images[0])[1])
os.chdir('..')
cwd2=os.getcwd()
print(cwd2)
这是
之后的输出C:\Users\Polaius-Work\Desktop\New folder (2)\my_images\ascaris lumbricodes
ascaris lumbricodes 1 .jpg
ascaris lumbricodes 2 .jpg
C:\Users\Polaius-Work\Desktop\New folder (2)\my_images
Traceback (most recent call last):
File "duplicate_images.py", line 10, in <module>
os.chdir(path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'my_images/babesia divergen'
很明显os.chdir('')
正在运行,但它不识别第二个文件夹