I am trying to move some files in python, but they have spaces in the name. Is there any way to specifically tell python to treat a string as a file name?
listing = os.listdir(self.Parent.userTempFolderPath)
for infile in listing:
if infile.find("Thumbs.db") == -1 and infile.find("DS") == -1:
fileMover.moveFile(infile, self.Parent.userTempFolderPath, self.Parent.currentProjectObject.Watchfolder, True)
After I get the file from the listing, I run os.path.exists on it to see if it exists, and it never exists! Can somebody give me a hint here?
The spaces in the filenames are not the problem;
os.listdirreturns filenames, not full paths.You’ll need to add them to your filenames to test them;
os.path.joinwill do this for you with the correct directory separator for your platform:Note that I also simplified your filename tests; instead of using
.find(..) == -1I use thenot inoperator.