As the title says, I'm trying to get a list of all the files and directories in a directory, including their attributes (I'm looking for at least name, size, last modified, and is it a file or a folder). I'm using Python 3 on Windows.
I've tried listdir()
, and I get a list of files without attributes. I've tried listdir_attr()
, and I get a list of attributes, but no filenames - and I don't see anything that guarantees that those two lists will be in the same order, so as far as I know, I can't just process the two lists together.
Even if I just end up with a big string that looks like a regular FTP / Linux ls
listing, that's fine, I can parse that later. I just need anything that has each file or folder and at minimum the attributes I'm looking for for each.
Here's a sample program. The connection values are valid and can be used for testing, it's a public test SFTP server.
import pysftp
cnopts=pysftp.CnOpts()
# - I know this next line is insecure, it's just for this test program and
# just to get a directory listing.
cnopts.hostkeys = None
print('Connecting...')
with pysftp.Connection('test.rebex.net', username='demo', password='password',
cnopts=cnopts) as SFTP:
mydirlist = SFTP.??????
# ^^^^^^ What goes here?
print('Result:')
print(mydirlist)