No such file or directory while trying to read files in a directory python

前端 未结 1 1749
迷失自我
迷失自我 2020-12-22 12:28

I have this code which lists the files in the directory and parses each one of them with my function.

paths = []
for filename in os.listdir(r\"C:\\Program Fi         


        
相关标签:
1条回答
  • 2020-12-22 12:49

    os.listdir() returns filenames, not paths. Join them with the directory name to make absolute paths:

    path = r"C:\Program Files (x86)\Folder\Folder"
    for filename in os.listdir(path):
        with open(os.path.join(path, filename)) as f:            
    
    0 讨论(0)
提交回复
热议问题