首页 > 解决方案 > 我在尝试创建 for in 循环时收到 FileNotFoundError

问题描述

我正在制作一个image classifier. 我已经成功创建了文件夹,并且我手动将必须从 google 放入的.txt files文件linksimages放入每个文件夹中。

我现在正在尝试将download每个图像中的图像.txt file either放入每个文件夹类别内的文件夹中,or放入每个也具有 .txt 文件的类别文件夹中,但是我不断收到错误消息。请帮忙。

我将它们manually放在.txt files每个文件夹中,就像它们在父文件夹名称中一样PLANTS,但这并没有什么不同。

我希望从带有谷歌图像链接的 .txt 文件中将所有图像下载到各自的文件夹中,但它不起作用,无论 .txt 是在主 PLANTS FOLDER 内还是在 PLANTS 文件夹内的每个类别文件夹内

相反,我收到以下错误

FileNotFoundError

请参阅随附的屏幕截图

在此处输入图像描述

&

在此处输入图像描述

标签: python-3.xjupyter-notebookgoogle-colaboratoryfast-ai

解决方案


Long filenames or paths with spaces are supported by NTFS in Windows NT. However, these filenames or directory names require quotation marks around them when they are specified in a command prompt operation. Failure to use the quotation marks results in the error message.

 for i in range(len(folders)):
        path = "content/gdrive/My Drive/Colab Notebooks/Flowers/PLANTS"
        #for creating directory we need path class object so below this: 
        dest_for_creating_directory = path/folders[i]
        #for searchi directory which have spaces we need doubleQuotations that  
        #why user below one in download image function instead of dest. 
        dest_for_searching_directory = path+"/"+folders[i]

Note: its better practice to write folder/file name without space more info


推荐阅读