我正在使用 python-fabric 库构建一个远程服务器管理工具,并且正在寻找一种检索远程服务器上目录的文件列表的好方法。目前我正在使用 run("ls dir") 并手动拆分返回字符串,这看起来很可怕并且非常依赖于体系结构。 fabric.contrib.files 似乎不包含任何有用的东西..
非常感谢您的建议。
干杯, R
最佳答案
这是怎么回事?
output = run('ls /path/to/files')
files = output.split()
print files
检查 documentation on run()
更多技巧。
关于 python Fabric : How to retrieve a filelist of a dir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6628263/