python - 在 Python Paramiko 中检索具有完整路径的目录中的文件列表
问题描述
我有这个代码使用本地文件:
path = r'/localhost_path/'
for filename in os.listdir(path):
subpath = os.path.join(path, filename)
if subpath.endswith('.txt'):
print("TXT")
我试图用带有 Paramiko 的 SFTP 替换它,但它没有用。Paramiko 没有.join
选择——如何解决这个问题?
解决方案
如果您的问题是如何使用完整路径检索给定目录中的文件列表,您可以使用以下命令:
path = "/remote/path"
for filename in sftp.listdir(path):
fullpath = path + "/" + filename
print(fullpath)
推荐阅读
- c++ - 返回一个weak_ptr 成员变量
- laravel - CRON JOB - 为不同时区安排 Laravel 命令 - 管理不同地区
- javascript - 将引导主题转换为角度 9 后,轮播指示器不起作用
- c# - Sql server 游标与 While 循环的性能
- python - Django 中的 request.session["name"] 会创建一个新列表吗?
- python - AWS Boto3“类型错误:列表索引必须是整数或切片,而不是 str”
- c++ - 返回给定单词所在的桶号
- django - 如何在 django (2.1) 中添加自定义选择字段?
- visual-studio-code - Intellisense 建议不显示 provideCompletionItems 返回的项目
- c# - 如何强制 .Net Core 项目始终根据文件扩展名采取文件 Build Action