To fetch files by glob patterns use the glob
module:
import glob
contentlist = glob.glob(test[0])
Pergunta
I am trying to read a line from a file and use the content as an argument for the os.listdir method
f = open('test.txt', "r+")
test = f.readlines()
contentlist = []
contentlist = os.listdir(test[0])
which returns
"WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'c:\\test\n\\*.*"
which makes sense because that's how test[0] is written in the array. But how do I get the "c:\test\" version out of that array?
Solução
To fetch files by glob patterns use the glob
module:
import glob
contentlist = glob.glob(test[0])
Outras dicas
Try this out
import glob
f = open('test.txt', "r+")
test = f.readlines()
contentlist = []
contentlist = glob.glob(test[0])
print contentlist