-2

I'm just learning Python, got Python 2 installed and was trying to figure out how you can go about testing whether a directory contains any files (as well as directories). Could anyone help? I've seen similar examples not related to the ftplib library though.

Ant

Ant
  • 1

2 Answers2

0

Once you've created your FTP connection you can call .dir() with an optional argument to check inside a specific folder which will give you a directory listing.

Christian Witts
  • 11,375
  • 1
  • 33
  • 46
  • Sorry, I should of explained more. I'm basically wanting to monitor a directory because this particular directory is where error logs are dumped. The OS creates a folder inside, I don't know the same of the folder exactly since the error logs are named by the current timestamp. I'm simply wanting to see if a folder has folders inside of it. The dir() function (from what I can see) allows you to pass an argument to look inside a particular folder. – Ant May 11 '12 at 14:23
  • `.dir()` will return you basically the equivalent of `ls` so you can then parse the output returned to you to find what you're looking for. – Christian Witts May 14 '12 at 07:12
0

You could do an os.listdir on the directory you are interested in, and test the items in the returned list to see if the items are files are directories with os.path.isdir.

Don't understand how any of this is related to ftp, though.

Pierce
  • 564
  • 2
  • 8
  • I'm connected to an FTP, I'm wanting to see the size of a directory on a live server. – Ant May 11 '12 at 14:56