简体   繁体   中英

No such file or directory

在此处输入图像描述 I have faced error I had worked with this code before but now:

error

FileNotFoundError: [Errno 2] No such file or directory: 'pattern2_list.txt'

I use Python 3.8

import os
import shutil

with open ("pattern2_list.txt") as pattern_list_file: 

    pattern_data = pattern_list_file.read ()
    pattern_list = pattern_data.split('\n')[:-1]

file_name_list = [file_name for file_name in os.listdir('2020')]

for file_name in file_name_list:
    for pattern in pattern_list:
        if pattern in file_name:
            shutil.move("2020/" + file_name, "new_dir/"+ file_name)

Make sure that the file pattern2_list.txt is present in the same working directory. If you are in same directory and still it is not working then open a new folder and inside it create your python file with .py extension.Inside same folder paste the pattern2_list.txt file and then try to use it. If still facing issue then check your python path in environment variable and if possible restart your system then open vs code.

Hope it will help you..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM