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.
获取存储在某个文件夹中的所有文件的文件名非常容易,您可以轻松地将其写入文件(以您想要的任何格式):
import os
filenames = os.listdir('path to directory')
logFile = open('filenames.txt')
for name in filenames:
logFile.write(filename)
logFile.close()
您必须在服务器上执行此代码,因此请确保您可以在其上执行 Python 代码。
完成后,您可以使用urllib2
模块从服务器中检索它:如何使用 Python 通过 HTTP 下载文件?