【问题标题】:Python giving FileNotFoundError for file namePython为文件名提供FileNotFoundError
【发布时间】:2020-11-04 14:40:47
【问题描述】:

我试图遍历目录中的文件,如下所示:

with open(video_list, 'r') as imf:
    index = []
    for id, line in enumerate(imf):

        video_label = line.strip().split()

        video_name = video_label[0]  # name of video
        label = rectify_label[video_label[1]]  # label of video

        video_path = os.path.join(video_root, video_name)  # video_path is the path of each video
        ###  for sampling triple imgs in the single video_path  ####

        img_lists = os.listdir(video_path)
        img_lists.sort()  # sort files by ascending
        img_count = len(img_lists)  # number of frames in video
        num_per_part = int(img_count) // 3

但即使文件存在,Python 也会抛出 FileNotFoundError:

---> 36             img_lists = os.listdir(video_path)
 37             img_lists.sort()  # sort files by ascending
 38             img_count = len(img_lists)  # number of frames in video

FileNotFoundError: [WinError 3] 系统找不到指定的路径:'C:/Users/m_rayeni/Emotion-FAN/Data/Train/Fear/013736360'

那么这里出了什么问题?

【问题讨论】:

    标签: python


    【解决方案1】:

    我认为这里的错误是您在文件名中使用正斜杠而不是反斜杠。 您当前的路径是“C:/Users/m_rayeni/Emotion-FAN/Data/Train/Fear/013736360” 应该是"C:\Users\m_rayeni\Emotion-FAN\Data\Train\Fear\013736360"

    这很可能也不起作用,您需要像 "C:\\Users\\m_rayeni\\Emotion-FAN\\Data\\Train\\Fear\\013736360" 那样转义反斜杠

    或使用原始刺痛,例如 - r"C:\Users\m_rayeni\Emotion-FAN\Data\Train\Fear\013736360"

    【讨论】:

      猜你喜欢
      • 2015-05-02
      • 2017-07-11
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 2021-07-23
      相关资源
      最近更新 更多