How to get file names from Web directory - Python code
Question: I would like to know how to get a list of filenames (.jpg image files) that
are stored on a server.

I am looking for code which stores all the filenames (with their extension) in
an Excel table or in the CSV format.

Any tips will be very helpful.


Answer: It's pretty easy to get the filenames of all files stored in a certain folder,
and you can easily write it in a file (in whatever format you want) :

    
    
    import os
    filenames = os.listdir('path to directory')
    logFile = open('filenames.txt')
    for name in filenames:
        logFile.write(filename)
    logFile.close()
    

You must execute this code on your server, so make sure you can execute Python
code on it.

Once that's done, you can retrieve it from your server using the `urllib2`
module : [How do I download a file over HTTP using
Python?](http://stackoverflow.com/questions/22676/how-do-i-download-a-file-
over-http-using-python)

