How do I parse a listing of files to get just the filenames in Python?

前端 未结 7 1532
一向
一向 2021-02-10 23:50

So lets say I\'m using Python\'s ftplib to retrieve a list of log files from an FTP server. How would I parse that list of files to get just the file names (the last column) ins

7条回答
  •  抹茶落季
    2021-02-11 00:22

    If the FTP server supports the MLSD command, then please see section “single directory case” from that answer.

    Use an instance (say ftpd) of the FTPDirectory class, call its .getdata method with connected ftplib.FTP instance in the correct folder, then you can:

    directory_filenames= [ftpfile.name for ftpfile in ftpd.files]
    

提交回复
热议问题