On Windows 10, running Debian in WSL2, I have a desktop shortcut to a bash script.
I’d like to drag-and-drop a number of files onto the shortcut, and have the script process them. It works fine if there ARE spaces in the filename, but if there are no spaces, then the path ends up with all slashes removed. For example, C:UsersMefile.txt
would become C:UsersMefile.txt
The shortcut which receives the dropped files is C:WindowsSystem32wsl.exe -- /home/myuser/bin/hi.sh
The first two lines of the script "hi.sh"
#!/bin/bash
echo "Received $@"
If I drop these files on it:
C:UsersMeDesktopfile-no-spaces.wav
C:UsersMeDesktopFile With Spaces.wav
It outputs:
Received C:UsersMeDesktopfile-no-spaces.wav C:UsersMeDesktopFile With Spaces.wav
There are utilities like wslpath, but they’re of no use if the initial files are already stripped. Any suggestions how to get windows to not strip out the backslashes?
2
Answers
In the end, I'm going with this.
%~1
as opposed to %1 or %1%, is the only method that is consistent with having no quotes. So this loop then adds quotes and collects all the parameters into %params%Instead of shortcut, create
hi.cmd
as follows :and drag&drop files onto
hi.cmd
Update
This seems to work, but you need to process each file separately: