Les,
I'm retrieving the selection(s) using
Code:
prompt $g
::"%~dp0\FileDialog.exe" Open "Text files (*.txt)|*.txt" "D:\Desktop"
"%~dp0\FileDialog.exe" Open "All files (*.*)|*.*" "D:\Desktop"
set UseExpresssion=Reg Query "HKCU\Software\FileDialog" /v "ItemList"
For /F "tokens=* " %%X in (' %UseExpresssion% ') Do Set "SelectedFile=%%X"
echo "%SelectedFile%"
:: Remove unwanted preamble from the extracted value
Set "SelectedFile=%SelectedFile:*REG_SZ =%"
echo "%SelectedFile%"
If "%SelectedFile%"=="" (Echo File selection was cancelled) Else (Echo SelectedFile is "%SelectedFile%")
Pause to check
About " versus csv
I might select a file/folder whose path contains a comma or an ampersand though so a csv format would also have to use quotes to cope with that.
- Separation by " allows a simple For loop to extract each selected file from the result
- I tested this by pausing during the retrieval then manually altering the Registry entry to a "----" format
Code:
::"%~dp0\FileDialog.exe" Open "Text files (*.txt)|*.txt" "D:\Desktop"
"%~dp0\FileDialog.exe" Open "All files (*.*)|*.*" "D:\Desktop"
Pause to job the Registry entry manually to a format of "---" "---"
set UseExpresssion=Reg Query "HKCU\Software\FileDialog" /v "ItemList"
For /F "tokens=* " %%X in (' %UseExpresssion% ') Do Set "SelectedFile=%%X"
:: Remove unwanted preamble from the extracted value
Set "SelectedFile=%SelectedFile:*REG_SZ =%"
echo "%SelectedFile%"
For %%X in (' %SelectedFile% ') Do Set "ThisFile=%%X"
pause to check - each selected file is set in turn as %ThisFile% and a simple subroutine could be used to capture & process each one separately
"Folder selection is done by setting the first parameter to Folder" - OK. That works. Thanks.
About console retrieval
I tried to apply the same retrieval approach but failed every time.
I tried lots of variations around
Code:
set UseExpresssion="%~dp0FileDialog.exe" Open "All files (*.*)|*.*" "D:\Desktop" false
For /F "tokens=* usebackq" %%X in (` "%UseExpresssion%" `) Do Set "SelectedFile=%%X"
echo "%SelectedFile%"
pause to check
but without success.
Amongst my attempts were' instead of `
^| instead of |
^" instead of "
omitting usebackq
omitting UseExpresssion and putting the expression into the For command directly instead
The really frustrating part is that the expression used is similar to examples that do work. Amongst my examples areFor /F "tokens=*" %%V in (' Dir "E:\Fred\*.jpg" /s /b ') do echo %%V
andfor /F "tokens=*" %%X IN ('%UseExpresssion% ^| find /i "%FindString%"') do Call :Interfaces "%%X"
and, except for the additional complication of escaping the | and possibly some of the ", my example expressions are in the same pattern as the failing one.
I decided that I must be stupid today. I'll have another look tomorrow.
All the best,
Denis