Python Fabric: How to retrieve a filelist of a dir

Ricw picture Ricw · Jul 8, 2011 · Viewed 10.2k times · Source

I'm building a remote server admin tool using the python-fabric library and am looking for a good way of retrieving a filelist for a directory on the remote server. Currently I'm using run("ls dir") and am manually splitting the return string, which seems horrendous and very much architecture dependent. fabric.contrib.files doesn't seem to contain anything of use..

Suggestions much appreciated.

Cheers, R

Answer

jathanism picture jathanism · Jul 9, 2011

What's wrong with this?

output = run('ls /path/to/files')
files = output.split()
print files

Check the documentation on run() for more tricks.