I'm learning xonsh. I tried the following simple script, but it fails at zipinfo -1 $mzip_str, specifically at expanding mzip_str.
#!/usr/bin/env xonsh
from pathlib import Path
my_path = Path('/path/to/downloads/')
dir_list = my_path.glob('*.zip')
for my_zip in dir_list:
mzip_str = str(my_zip)
zip_dir_names = $(zipinfo -1 $mzip_str | grep -E '.*/$')
print(zip_dir_names)
In the xonsh shell, I get these results:
➤ zip_dir_names = $(zipinfo -1 mzip_str)
zipinfo: cannot find or open mzip_str, mzip_str.zip or mzip_str.ZIP.
➤ zip_dir_names = $(zipinfo -1 $mzip_str)
zipinfo: cannot find or open $mzip_str, $mzip_str.zip or $mzip_str.ZIP.
➤ zip_dir_names = $(zipinfo -1 @mzip_str)
zipinfo: cannot find or open @mzip_str, @mzip_str.zip or @mzip_str.ZIP.
➤ zip_dir_names = $(zipinfo -1 !mzip_str)
zipinfo: cannot find or open mzip_str, mzip_str.zip or mzip_str.ZIP.
From the official tutorial
So the relevant line should look like (Untested as I don't have this
xonshinstalled):But it sounds like
$()returns a string and you probably wantzip_dir_namesto be a list if you want to do anything with it but print it. Something likemight work better. Or just use the standard Python zipfile module module instead of an external program, of course.