Wanted: Sample scripts to cannibalize

Page 3 of 6 FirstFirst 12345 ... LastLast

  1. Posts : 745
    Windows 10/11
       #21

    @Try3 and @pokeefe0001 I've updated FileDialog.exe with the following enhancements:

    1. The selected item(s) are now written to HKCU\Software\FileDialog\ItemList (REG_SZ) and also to HKCU\Software\FileDialog\ItemListM (REG_MULTI_SZ)
      For backwards compatibility, a single item name is still written to the Default value.
    2. The selected item(s) are now also written to the Console.
    3. Special folders, such as ThisPC, can now be used for the StartPath.
    4. Folder is now a DialogType option in addition to Open and Save.

    The new version is available from here: FileDialog.exe

    Please test and let me know if there are any issues. My main concern is that I'm currently returning multi-select results as a string of paths separated by "|" (i.e. vertical bar or pipe character). This is fine for VBScript as you can see by Example2.vbs. However, I'm not sure it's going to be okay for batch files.
      My Computer


  2. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #22

    Try3 said:
    If it's only one or two variables each way then I normally use a method suggested by Tom Lavedas years ago
    Les,

    I found that I had a demo batch-PS script of the Tom Lavedas method lying around and thought you'd be interested.
    The batch script calls the PS and passes two arguments to it.
    The PS script plays around stupidly with the passed arguments just so there's something new to see in the demo's returns.
    The batch script accepts the returns and echos them.
    - the "FF" were just there so I could check for unexpected spaces
    - You'd normally know what names you wanted to assign to each returned variable but I used incremental names with Call Echo instead.

    Demo-MultipleVars.zip

    I've just seen that you've posted a revised FileDialog.exe
    I'll play with it over the weekend and post back on Monday.

    All the best,
    Denis
      My Computer


  3. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #23

    Les,

    My only concern about v2 so far is that it would be easy to separate multiple selections from the Registry entry if they were each quoted & separated by a space.
    "D:\Desktop\MBAM exclusions.png" "D:\Desktop\Screenshot (1085).png"
    but separating then when they are joined by | is awkward.
    - Whatever the results are going to be used for it seems, to me, that each selected file is liable to be processed on its own - so separation is essential.

    Was there some particular reason for choosing |?

    I'm having to stick with retrieving results from the Registry because I cannot get my normal method of retrieving values directly from the console to work in this case.

    Denis
      My Computer


  4. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #24

    Les,

    I have now also tried to select a folder but the dialog does not respond at all when I do so. I suspect that I have misunderstood your instructions for folder selection.
    - I have tried with both the Open and Save dialogs.
    - My previous [successful] tests were file selections using the Open dialog.

    Denis
      My Computer


  5. Posts : 745
    Windows 10/11
       #25

    Try3 said:
    Les,

    My only concern about v2 so far is that it would be easy to separate multiple selections from the Registry entry if they were each quoted & separated by a space.
    "D:\Desktop\MBAM exclusions.png" "D:\Desktop\Screenshot (1085).png"
    but separating then when they are joined by | is awkward.
    - Whatever the results are going to be used for it seems, to me, that each selected file is liable to be processed on its own - so separation is essential.

    Was there some particular reason for choosing |?

    I'm having to stick with retrieving results from the Registry because I cannot get my normal method of retrieving values directly from the console to work in this case.

    Denis
    It was just easier to leave them unquoted and separate with a character that cannot be used in a filename. Tonight, I'll change it to use quotes.Would a comma separator be okay? Then the result will be CSV format, which is really easy to process in some languages.

    I also may change the parameter order so that FileFilter comes after StartPath, since FileFilter is not applicable to Folder selection. Or I may make FileFilter an optional parameter.

    I wonder why console retrieval isn't working. I'll try to take a look at that too. Did you already point me to the code you use? I'll check back on the earlier replies.

    Just saw your previous message about folder selection. Folder selection is done by setting the first parameter to Folder, instead of Open or Save. For now, FileFilter must be set to something (e.g. "") and StartPath to wherever you like.
      My Computer


  6. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #26

    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 are
    For /F "tokens=*" %%V in (' Dir "E:\Fred\*.jpg" /s /b ') do echo %%V
    and
    for /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
      My Computer


  7. Posts : 720
    Win10 x64 Pro - 2 desktops, 2 laptops
    Thread Starter
       #27

    I've finally gotten out from under higher priority stuff and can spend a little time working on this this weekend.

    FileDialog is, indeed, the most straightforward of the solutions, but unless there is a way to display some user instructions I probably won't be able to use it (for my task at hand). Let me describe the target demographic for this function. That will hopefully explain whey your expanded HTA solution and the FileDialog solution won't work. (Details of this description are mostly aimed at the HTA solution.)

    Some of these users
    • probably don't know our music library is a folder named FDMusic (so wouldn't understand "Base Folder")
    • probably don't know that an M3U file is a playlist
      (They will have to be given explicit instructions on how to find their playlist file.)
    • don't know what a path is, don't know that an M3U playlist contains paths, and don't know that the paths in their playlist have to be changed to match the library's path

    They just know that they have to import a playlist that was exported (probably by themself) from a different installation.

    In other words, the FileDialog solution does not given them enough information to select their playlist file, and the expanded HTA solution asks for far too much information. (Luckily, all that information can be programmatically obtained.)

    The original HTA solution asks just the right amount of information, but I would have to add some instructional verbiage.

    I have a vbs script that does all the processing I need but cannot figure out how to invoke it from hta. I've tried inserting the vbs code into the hta (and fighting issues like not having a Wscript object ... or something like that), but have run into an error - probably a syntax error - that results in almost the last statement in hta file flagged as an error. I know the error has to be in the scripts section, not in
    Code:
    <input type="file" id="f1" style=width:40em oninput="ProcessFile()">
    I suspect it's a mismatched quote somewhere, but I can't find it.
    Is there a way I can invoke the vbs script (including a passed argument) from hta?
      My Computer


  8. Posts : 745
    Windows 10/11
       #28

    pokeefe0001 said:
    I have a vbs script that does all the processing I need but cannot figure out how to invoke it from hta. I've tried inserting the vbs code into the hta (and fighting issues like not having a Wscript object ... or something like that), but have run into an error - probably a syntax error - that results in almost the last statement in hta file flagged as an error.

    Is there a way I can invoke the vbs script (including a passed argument) from hta?
    Yes, that can be done, but you'll have much better options available if you keep it all in the HTA. Can you post what you have so far? I'm sure I can sort out the error once I see the code.
      My Computer


  9. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #29

    Les,

    I have noticed one additional thing that differs between the folder & file dialogs of FileDialog.exe.
    Whilst Select folder appears helpfully in the Title bar & on the button, the Select file dialog just says "Open" instead [which is misleading]. Perhaps that's a constraint of using the common dialogs for the job and so has to be accepted.

    Denis
    Last edited by Try3; 10 Dec 2021 at 21:43.
      My Computer


  10. Posts : 745
    Windows 10/11
       #30

    Try3 said:
    I have noticed one additional thing that differs between the folder & file dialogs of FileDialog.exe.
    Whilst Select folder appears helpfully in the Title bar & on the button, the Select file dialog just says "Open" instead [which is misleading]. Perhaps that's a constraint of using the common dialogs for the job and so has to be accepted.
    Actually, that's just a matter of adding a parameter for dialog title, which I've now done. I've also revamped the parameters so that they're all optional (except dialog type) and can be specified in any order. I'll update the files soon. Just doing a little more testing...
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:49.
Find Us




Windows 10 Forums