您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Python中通过SFTP连接后如何列出目录中的所有文件夹和文件

在Python中通过SFTP连接后如何列出目录中的所有文件夹和文件

一种快速解决方案是检查中lstat的每个对象的输出ftp.listdir()

这是列出所有目录的方法

>>> for i in ftp.listdir():
...     lstatout=str(ftp.lstat(i)).split()[0]
...     if 'd' in lstatout: print i, 'is a directory'
...

文件是相反的搜索

>>> for i in ftp.listdir():
...     lstatout=str(ftp.lstat(i)).split()[0]
...     if 'd' not in lstatout: print i, 'is a file'
...
python 2022/1/1 18:25:12 有166人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶