I've been working on a little python program that simply connects to my nas and cleans up some of my filenames. I'm using the python ftp lib to connect to the nas and do my things.
I'm just wondering here if anyone has a good way of checking whether a file on the server is actually a file or if it is a folder?
This is what I'm using:
try:
ftp.cwd(line)
#If we got here then this "line" is a folder
# Do my folder stuff
ftp._ftp.cwd('..') #don't forget to go back after it worked
except ftplib.error_perm:
#An exception! So this means we are dealing with a file
#So do some file stuff
except:
#Sometimes you just can't get in the folder for some reason
falsepos = falsepos + 1
I could look at the output of the directory listing but this is not the same on different platforms and I am trying to build something what will keep on working even if I for some reason replace my nas.
There is also a little bug in my code. Some times it still regards a folder as a regular file...
Your opinions?
(I'm using Python 2.7)