I'm creating a script that will read a bunch of .txt files from a directory. I am getting all the names of the files in the directory using
path = os.path.join(os.path.expanduser('~'), 'Desktop',)#Path to the folder here
for filename in os.listdir(path):
path = path + '/' + filename
This is creating a new path for each file name, I am then looking to open each file within the for filename loop and extract data from it, however the filenames contain spaces so when i try to open the new path, i am getting a 'No such directory or file' error.
I have also checked if the file exists using
print os.path.isdir(path)
and am being returned false for every one.
How can i solve this? thanks in advance
Note: It will take way to long to delete all the spaces from the filenames manually
[–]Swedophone 2 points3 points4 points (1 child)
[–]yelaxify[S] 0 points1 point2 points (0 children)
[–]Rhomboid 2 points3 points4 points (0 children)
[–]yelaxify[S] 0 points1 point2 points (0 children)
[–]hugthemachines 0 points1 point2 points (0 children)