Trouble passing directory with spaces to python script

I'm trying to make a python script that iterates over all files in the current directory and does stuff to them. I just have a button that calls python "C:\Users\Kuro\Downloads\script.py" {sourcepath$} and then the script just performs an os.walk over it, for root, dirs, files in os.walk(sys.argv[1]):. Issue is, if the current directory has a space in the name, like \New folder, the python script errors out. When I run this normally from the command line I get no issues, so I don't know what's going on. I don't know what the error is because the execution window closes immediately.

Do you know what might be going on?

Maybe just put {sourcepath$} in " "?

That makes it error out for any directory I run it from, space or no space, unfortunately.

Would be too easy haha.
There are some modifiers, I have no idea if one could work though:
https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Codes_for_passing_paths.htm

I think I might've figured it out. You need to append a backslash to the sourcepath. python "C:\Users\Kuro\Downloads\script.py" {sourcepath$}\

Odd fix, but it seems to be working as intended from all directories now.

Try {sourcepath|noterm} (without any extra slash added) for a cleaner solution.

1 Like

More detail about what's going on, from my old SetClip.exe docs: