Having no luck using a Python script to select files in Explorer, although I have achieved the same thing an EXE (written in C#) but cannot get the Python script to execute:
the C# EXE command:
Code:
"F:\[Source]\[Classic Shell Assistants]\Select Files\Select same name\SelSameName.exe" "%5" "%2"
and the Python script
Code:
"F:\[Source]\[Classic Shell Assistants]\Select Files\Select same name\SelSameName.py" "%5" "%2"
Is there something I should change in the command ?
Just for completeness, here are the contents of the script which works when I run it manually and feed it the required arguments:
Code:
import glob, re, sys, os.path
def main(args):
if len(args) == 2:
out_file = args[0];
sel_file = args[1];
dirname, sel_file = os.path.split(sel_file)
sel_file, _ = os.path.splitext(sel_file)
#print(sel_file)
rx = re.compile(r"[a-z 0-9]+", re.IGNORECASE);
m = rx.match(sel_file)
#print(m)
s = m.group().strip()
print(s)
#var files = Directory.GetFileSystemEntries(dir, s + "*.*");
#files = os.listdir(dirname)
files = glob.glob( os.path.join(dirname, s) + "*.*", recursive=False)
#print(files)
sb = ['Select']
for file in files:
_ , fname = os.path.split(file)
sb.append(fname)
ss = '\n'.join(sb)
#print(ss)
with open(out_file, "w", encoding="utf-8") as f:
f.write(ss)
#just for testing
with open('f:/logz.txt', "w", encoding="utf-8") as f:
try:
f.write(str(len(sys.argv)) + '\n')
f.write(str(sys.argv) + '\n')
f.write(__file__)
except Exception as ex:
print(ex)
main(sys.argv[1:])