1

I'm trying to write a script that searches my network volume and returns a list of paths and files. I'd then like to use that list in a subprocess that runs a windows explorer search, allowing the user to drag and drop the files from the search browser to wherever. Where I'm getting hung up is passing the variable (list) into the subprocess string.

example:

foo = 'returned list'
subprocess.Popen(f'explorer /root,"search-ms:query={foo}"')

The string is part of a windows explorer search argument

search-ms:parameter=value[&parameter=value]&

is from MSDN Getting started with parameter-value arguments. https://msdn.microsoft.com/en-us/library/windows/desktop/ff684385(v=vs.85).aspx

If I run the subprocess string with a specific parameter, say genericFileName.fileExt, and the file(s) exists:

subprocess.Popen(f'explorer /root,"search-ms:query=genericFileName.fileExt"')

The subprocess launches explorer and displays the file(s)

When I try using a variable, the subprocess opens the explorer, but does not return a search result. I want to be able to use a variable within the subprocess string

So

"search-ms:query={foo}" 

{foo} is the variable in the subprocess string

Any help is greatly appreciated.

Thank you again

laplant76
  • 23
  • 1
  • 4
  • 1
    Possible duplicate of [String formatting in Python](https://stackoverflow.com/questions/517355/string-formatting-in-python) – pppery Jul 14 '17 at 02:28

1 Answers1

0

figured it out:

import subprocess
filePath = 'someFile.ext'
localPath = r'C:\someDirectory'
cmd = r'explorer /root,"search-ms:query=%s&crumb=folder:%s&"'
subprocess.Popen(cmd % (filePath, local_path))
laplant76
  • 23
  • 1
  • 4