【发布时间】:2015-01-19 01:34:12
【问题描述】:
我想从内存中 ftp 文件夹的所有文件夹和子文件夹中读取所有图像文件 (*.jpg),但不一定要下载它们。文件夹结构的深度不同,我需要的文件可以在主文件夹或任何子文件夹中。
我尝试在循环中使用 nlst,但我只是得到一个文件列表并且无法单独读取 jpg 文件。一旦我读取了一个文件,我计划使用 opencv 对该文件进行一些处理,并在一个数组中提取特定信息,然后转到下一个文件。
这是我的代码:我还不能浏览子文件夹。
log = []
file_list = []
for name in ftp.nlst():
print "listing: " + name
ftp.cwd(name)
ftp.retrlines('LIST',callback=log.append)
#lines = lines.split("\n") # This should split the string into an array of lines
#filename_index = len(lines[0]) - 1
files = (line.rsplit(None, 1)[1] for line in log)
for file in files:
if file.split('.')[-1] == "jpg":
# whatever
file_list.append(file)
ftp.cwd('../')
感谢任何帮助。
【问题讨论】: