It is currently Thu Mar 28, 2024 7:50 am

All times are UTC - 8 hours [ DST ]


Forum rules


Please, keep discussions on topic and in the right forum. The start menu topics go into the Classic Start Menu forum, etc. This makes it easier for people to locate topics they are looking for.
If you get a satisfactory response to your question, please mark the topic as "solved". Click the green √ button in the bottom-right of the post.



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Jan 09, 2019 6:49 pm 
Offline

Joined: Sun Sep 21, 2014 8:45 pm
Posts: 2
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:])


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group, Almsamim WYSIWYG Classic Shell © 2010-2016, Ivo Beltchev.
All right reserved.