Wanted: Sample scripts to cannibalize

Page 2 of 6 FirstFirst 1234 ... LastLast

  1. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #11

    Could you get all your users to give the same disk label to their USBs containing their portable MediaMonkey?
    - For example, all my computers have a local backup USB/partition called Bertie.
    - The opening section of my backup scripts searches for a disk called Bertie and retrieves its drive letter.
    - So differences in drive letters are not a problem for my scripts, the correct one is always found by the script without the user having to do anything other than run it.
    - I posted my script in a previous thread of yours - Revised Identifydrives.bat [post #36] - TenForums
    - You will be able to simplify the script because you will definitely only want to use it one-way [pass drive label, get drive letter] and the script can also cope with the opposite [pass drive letter, get drive label].

    If I have understood your posts correctly,
    - there is one master copy of the playlist
    - everybody has a playlist in the same 'relative path' in their USBs.
    So your task is simply to copy a file from one location to a corresponding location in a different drive letter e.g.
    From
    F:\folder1\Folder2\Folder3\CurrentPlaylist.msu
    to
    G:\folder1\Folder2\Folder3\CurrentPlaylist.msu
    where G is unknown,
    and then carry out the same substitution of G:\ throughout the playlist file once it's in place.

    Have I understood correctly? Can you get them all to name their USBs?

    Denis
    Last edited by Try3; 06 Dec 2021 at 10:41.
      My Computer


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

    LesFerch said:
    Question: Do you want to prompt the user to choose a single file, multiple files, or a folder of files?
    I'm envisioning selection of a single file. I suppose it would be nice to allow multiple files but I don't think that is necessary (and that would complicate the processing code a bit). I don't se any need to allow a folder of files to be selected.

    What I do envision as necessary is that the selection process would start at the "My Computer" level with the user expanding levels downward until the file is found. I don't want to make any assumptions about the path to the file.

    mngerhold said:
    ... I don't know if MediaMonkey forces absolute paths, or can be made to work with relative ones. As I now see that the m3u files are plaintext, then editing won't be that tricky - but still a lot of work every time an update is required. I shall bow out to Les.
    MediaMonkey allows relative paths, but that works only if the library and playlist file have the same relative path. In my case they will always be on different drives. I assume that is the way relative paths are expanded - the absolute path is created based on the absolute path of the file containing the relative path (or something like that).

    Try3 said:
    Could you get all your users to give the same disk label to their USBs containing their portable MediaMonkey?
    I could because I supply the USB drives, but I have enough trouble keeping track of the flash drives when I'm updating them that I'd prefer to keep different names on the drives. The drive labels do all start with the same characters - "MM SBD #". (My maintenance scripts check for one and only one drive with that string in the label.)

    But my primary "maintenance" copy of the installation is on an internal drive on one of my computers. I would prefer that this new process to work there, too (without my having to hardcode in a test for that copy).

    Try3 said:
    ... - I posted my script in a previous thread of yours - Revised Identifydrives.bat [post #36] - TenForums
    That very well may be the script I cannibalized to get my
    Code:
    Set LabelMask=SBD MM #
    
    Set Drive=
    Set Extra=
    for /f %%D in ('wmic volume get DriveLetter^, Label ^| find /I "%LabelMask%"') Do (
       if defined Drive set Extra=%%D
       if not defined Drive set Drive=%%D

    Try3 said:
    If I have understood your posts correctly,
    - there is one master copy of the playlist
    - everybody has a playlist in the same 'relative path' in their USBs.
    So your task is simply to copy a file from one location to a corresponding location in a different drive letter e.g.
    From
    F:\folder1\Folder2\Folder3\CurrentPlaylist.msu
    to
    G:\folder1\Folder2\Folder3\CurrentPlaylist.msu
    where G is unknown,
    and then carry out the same substitution of G:\ throughout the playlist file once it's in place.
    I don't know if the details matters, but no, that's not quite right. MediaMonkey has its own internal playlist format that resides in an SQLite database. The M3U playlists are needed only for getting a playlist out of or into MediaMonkey.

    In our folkdance group, each week someone creates a new playlist. Some people create the list at out folkdance meetings. Others want to create it ahead of time and ask to take home one of our flash drives to create a playlist within MediaMonkey. This complicates keeping the flash drives in sync because we have multiple copies out sometimes for multiple weeks.

    It would be much simpler (for me) if these people could create M3U playlists outside of MediaMonkey, or from a MediaMonkey that is not necessarily in sync with the others, bring their M3U playlist to the folkdance meeting, and load it into the "production" MediaMonky. These playlists will certainly have different paths than production MediaMonkey, but as long as they will refer to some copy of our library so will have easily convertible paths.

    - - - Updated - - -

    Well, I've got everything working except the file selection dialog. I've found lots of folder selection vbs examples and a number of questions questions about file selection, but no successful examples. The vbs function BrowseForFolder even has a "include files" option, and when specified, files are displayed, but it gives an error if a file is selected. (It works fine if a folder is selected). There are a number of reports of this on the web so I know it's not just me. There are no reports of success (that I've found) with Win10 but it apparently worked in Win7 and 8.1.

    If anybody knows how to display a file selection dialog, please let me know. It obviously works in File Explorer.

    If anybody cares, here's my script so far (with the file selection result overridden with a hard coded path so the script will run.

    Code:
    Option Explicit
    
    dim filesys, pathname, infile, outfile
    ' Request the input M3U file name
       infile = SelectFile( "" )
       WScript.Echo "Selected File: """ & infile & """"
    
       infile = "D:\Temp\Playlist\Test playlist.m3u"
    
    ' Determine the path of the grandparent folder of this script.
    ' That folder will also contain the SBD Library and the MediaMonkey folder.
       Set filesys = CreateObject("Scripting.FileSystemObject")
       pathname = filesys.GetParentFolderName(filesys.GetParentFolderName(WScript.ScriptFullName))
    
    ' Point to the output file.
       outfile = pathname & "\MediaMonkey\Temp\Playlist.m3u"
    
    ' Open the input and output files.  If the output file already exists it will be overwritten.
    dim  intf, outtf, infs, outfs
    
        Set infs = CreateObject("Scripting.FileSystemObject")
        Set intf = infs.OpenTextFile(Infile, 1)
    
        Set outfs = CreateObject("Scripting.FileSystemObject")
        Set outtf = outfs.CreateTextFile(Outfile, True)
    
    ' Read a playlist record from the input file.
    ' Modify the record to use the path to the local copy of the music library and write the record.
    ' Close both files when done.
     
    Dim InLine, OutLine
    Dim intLineCounter
    
       intLineCounter = 0
    
       Do Until intf.AtEndOfStream
           InLine = intf.ReadLine
           Outline = Pathname & Mid(Inline,InStr(Inline,"\FDMusic"))
           outtf.WriteLine(OutLine)
           intLineCounter = intLineCounter + 1
       Loop
       outtf.Close() ' Close output file
       intf.Close()  ' Close input file
      My Computer


  3. Posts : 745
    Windows 10/11
       #13

    pokeefe0001 said:
    If anybody knows how to display a file selection dialog [in VBScript], please let me know.
    I provided several examples of how to do that in my earlier reply.

    Here's a first attempt at an HTA to update M3U paths. Please take a look and let me know if it's suitable or needs further refinement. Of course, it includes the file selection dialog. There is no easy way to start the file selection at "This PC" (aka "My Computer"), but the file selection does automatically remember what you chose last time, so that's usually going to be what the user wants.

    Here's the script:

    M3U Path Editor HTA
      My Computer


  4. Posts : 720
    Win10 x64 Pro - 2 desktops, 2 laptops
    Thread Starter
       #14

    Sorry. I saw the list but didn't recognize them as links. (They were colored but not underlined.) I'll see what I can do with them.
      My Computer


  5. Posts : 745
    Windows 10/11
       #15

    pokeefe0001 said:
    Sorry. I saw the list but didn't recognize them as links. (They were colored but not underlined.) I'll see what I can do with them.
    Cool, but before you do that, please take a look at the HTA I just posted (I just edited my reply).

    Wanted: Sample scripts to cannibalize-screenshot.png
      My Computer


  6. Posts : 720
    Win10 x64 Pro - 2 desktops, 2 laptops
    Thread Starter
       #16

    LesFerch said:
    1) HTA (recommended)
    2) VBScript that uses MSHTA to access a file dialog
    3) VBScript that uses PowerShell to access a file dialog
    4) A command line file dialog exe
    5) Using the OpenFileDialog method from the VBSEdit Toolkit
    The HTA option will allow you to easily expand on the interface. Just put your VBScript code in the "ProccessFile" sub.
    1. I've looked at both the old and new HTA samples. The old one does exactly what I asked for (and no more). The new version is obviously slicker and does much of the needed processing. I'll have to tweak it a bit to get it to do exactly what I want, but it's a great starting point. I gather "input type=file" results in the File Explorer-like selection popup to be displayed.
    2. This one is strange. It displays the files in the folder selected by some previous action. There may be some way to reset that previous path but I'm missing it.
    3. I think I'll skip PS for now even though this one may be good.
    4. I'm not sure how I would use this one.
    5. I don't have VBSEdit so I don't think this would do me any good.


    I'll look more into your HTA samples, but I won't be able to get at it for several days.

    Thanks for your help.
      My Computer


  7. Posts : 745
    Windows 10/11
       #17

    pokeefe0001 said:
    I gather "input type=file" results in the File Explorer-like selection popup to be displayed.

    This one is strange. It displays the files in the folder selected by some previous action. There may be some way to reset that
    Both the HTA example, and the VBScript code that calls MSHTA to open a file dialog, use the same input type=file. A starting path cannot be set, but it remembers where you last opened a file and starts there. To reset the starting path would require editing the LastVisitedPidlMRU registry key. It's a binary format and not documented AFAIK.

    pokeefe0001 said:
    I'm not sure how I would use this one [filedialog.exe].
    It's actually the simplest option. The filedialog.exe app writes the result to the registry, so it's used like this:
    Code:
    Set oWSH = CreateObject("Wscript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    oWSH.Run ".\FileDialog.exe Open ""*.m3u|*.m3u"" C:\",0,True
    File = oWSH.RegRead("HKCU\Software\FileDialog\")
    MsgBox File
    It accepts parameters for type of dialog (open or save), filter to be applied, and starting directory.

    pokeefe0001 said:
    I don't have VBSEdit so I don't think this would do me any good.
    Yes, a $59 lifetime license would be required for that option.
      My Computer


  8. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #18

    pokeefe0001 said:
    4. I'm not sure how I would use this one
    If you wanted to use it within a batch file, you could use something like this running from the same folder that you've putFileDialog.exe in -
    Code:
    prompt $g
    
    "%~dp0\FileDialog.exe" Open "All files (*.*)|*.*" "D:\Desktop"
    
    set UseExpresssion=Reg Query "HKCU\Software\FileDialog"
    For /F "tokens=* " %%X in (' %UseExpresssion% ') Do Set "SelectedFile=%%X"
    :: Remove unwanted preamble from the extracted value
    Set "SelectedFile=%SelectedFile:*REG_SZ    =%"
    If "%SelectedFile%"=="" Echo File selection was cancelled
    If Not "%SelectedFile%"=="" Echo SelectedFile is "%SelectedFile%"
    Pause to check
    - I stuck in a sample starting folder but you can start wherever you want.
    - You can play around with the file types shown - "Text files (*.txt)|*.txt"
    - The extra line with REG_SZ in it removes wanted characters from the result [this need is a by-product of the required data being saved in a Registry key's (Default) entry rather than a named entry].
    - I have not been able to get multi-selections working. They are selected, they appear in the dialog's FileName box but they are not sent to the Registry key.


    All the best,
    Denis
    Last edited by Try3; 08 Dec 2021 at 16:25.
      My Computer


  9. Posts : 745
    Windows 10/11
       #19

    Try3 said:
    - The extra line with REG_SZ in it removes wanted characters from the result [this need is a by-product of the required data being saved in a Registry key's (Default) entry rather than a named entry].
    - I have not been able to get multi-selections working. They are selected, they appear in the dialog's FileName box but they are not sent to the Registry key.
    When I have a moment, I'll revise the exe to support multi-select and put the result in a named registry entry (I think I had a reason for using the default entry, but can't remember now - maybe it was just my limited C# skills). While I'm at it, I might as well also write the result to the console, in case you just want to redirect it to a file and read it in that way. Another enhancement I'll try to add is a folder selection option in addition to the open and save options.

    Of course, this goes against my general position of discouraging batch files in favor of VBScript/JScript/HTA, PowerShell, or third-party scripting languages such as WinBatch and AutoIt, but what the heck.
      My Computer


  10. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #20

    Les,

    A specific Registry Value entry rather than (default) would be great. I know it would only save one action within the script but it would be so much tidier.
    I was getting mixed up with something else I'd just been looking at. I don't think using the (default) entry makes any difference to retrieving the data.

    I only mentioned multi-select to avoid giving an opposite impression. I appreciate that it could have many uses but I've never needed it within a script [but I often use File explorer & SendTo to pass multiple selections to a script].

    I think making use of the Registry as an intermediate location for variable values is fine.
    - If I have to pass many variables from one script to another [often batch script to PS then back again], I use an intermediary text file instead. I use a separate one for passing values back because it keeps everything easy to debug. I'm not sure but I think I chose this method in preference to the Registry method because it would be easier when handling large numbers of passed arguments.
    - If it's only one or two variables each way then I normally use a method suggested by Tom Lavedas years ago - Return a string variable from a vbs script to a batch file [post #6] - TenForums
    - - It works between batch scripts and PS as well.
    - - It can be used for as many variables as you want [the batch script's For loop takes care of all that are there].

    I did some work on using PowerShell to generate folder selection dialogs last year. I ended up getting the script to write the instructions in the FileName input box because all other options seemed worse. The selection was saved into a variable.
    Wanted: Sample scripts to cannibalize-technet2-verytidied-awkward-but-works-locnexperimentv2.png

    And its file selection variant also saved the selection into a variable.
    Wanted: Sample scripts to cannibalize-technet2-verytidied-awkward-but-works-locnexperimentv3-open-fileselection.png

    - Both were based on Getting the file location using openfiledialog in powershell - TechNet
    - Both can cope with spaces and ampersands [&] in folder/file names.
    - Both were my final drafts and were subject to very little testing.
    - Neither allows multiple selections.


    I eventually adopted a completely different solution for that project so did not progress dialogs any further but I do remember thinking that a combined file selection & folder selection tool would be very useful so I wish you well in that endeavour.
    - Mine had very few coding differences but their functions were distinct - one was only a folder selection tool, the other was only a file selection tool.

    All the best,
    Denis
    Last edited by Try3; 08 Dec 2021 at 16:27.
      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 20:45.
Find Us




Windows 10 Forums