import os
Current_Directory = os.getcwd()
CORPUS_PATHS = sorted([os.path.join("archive", directories) for directories in os.listdir(Current_Directory)])
filenames = []
for items in CORPUS_PATHS:
filenames.append(sorted([os.path.join(CORPUS_PATHS, fn) for fn in os.listdir(items)]))
print filenames
I run this code from a file called archive, and there are more folders in the archive, and each of these folders has one or more text files. I want to make a list that includes the path to each of these folders. However, the following error appears.
[Error 3] The system cannot find the path specified:
I currently have a python script where I wrote this code in the same folder as the archive, and this will cause this error. What should I do to stop this error and get all file paths.
I am not good at using os, and I don't use it often, so I apologize if this is a trivial question.
Edit
import os
startpath = "archive"
corpus_path = sorted([os.path.join("archive/", directories) for directories in os.listdir(startpath)])
filenames = []
for items in corpus_path:
print items
path = [os.path.join(corpus_path, fn) for fn in os.listdir(items)]
print path
, , , , . , , , , , , ,
File "C:\Users\David\Anaconda\lib\ntpath.py", line 65, in join
result_drive, result_path = splitdrive(path)
File "C:\Users\David\Anaconda\lib\ntpath.py", line 116, in splitdrive
normp = p.replace(altsep, sep)
AttributeError: 'list' object has no attribute 'replace'