Batch File to Execute All Files (or at least all URLs) in a Folder


  1. Posts : 108
    Windows 7 and 10
       #1

    Batch File to Execute All Files (or at least all URLs) in a Folder


    I have a folder containing these files:
    Code:
    Bruschetta Duet Recipe - Quick From Scratch Italian Food & Wine.URL
    Buffalo Chicken Deviled Eggs Recipe How to Make It.URL
    269 Chicken & Bacon Roll-Ups.URL
    Yeah, I'm hungry.
    What would be the desired syntax to automatically open all URLs in a specified folder? I think it would be something like this:
    Code:
    for /r %%A in (*) do "start Firefox *.url"
    but I'm not sure about the format or punctuation in the Firefox part.
      My Computer


  2. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #2

    Hello @raywood,

    I do NOT use Forefox, but I think you will also need to setup a variable linked to the Firefox .exe file [ Firefox Directory ].

    Alternatively, I found these for you . . .

    > Open Multiple URLs
    > Open Multiple URLs is an extension for Firefox and Chrome that can load several URLs in a couple of clicks
    > Bulk URL Opener

    I hope this helps.
      My Computer


  3. Posts : 2,800
    Windows 7 Pro
       #3

    Code:
    For /f %%a in ('dir /b "C:\recipes\*.*"') do ("%ProgramFiles%\Mozilla Firefox\firefox.exe" "%%a")
      My Computers


  4. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #4

    Hello @raywood,

    Ah, @MaloK beat me to it, I was just testing this using Google [ Same Concept ] for you.
      My Computer


  5. Posts : 108
    Windows 7 and 10
    Thread Starter
       #5

    I tried that and some variations, like this:
    Code:
    for /f "usebackq delims=" %%A in ('dir /b "W:\URLs\*.url"') do ("%ProgramFiles%\Mozilla Firefox\firefox.exe" "%%A")
    These persist in opening files like this in the browser:
    Code:
    file:///C:/WINDOWS/system32%00/dir%20/b%20W:/URLs/*.url
    What do you suppose that's all about?
      My Computer


  6. Posts : 7,607
    Windows 10 Home 20H2
       #6

    I have modified the code in my previous post (already deleted).
    The following CMD code works even if a URL file's name contains the special character &.
    Code:
    @echo off & Set "Folder=W:\URLs" 
    Set "Browser=%ProgramFiles%\Mozilla Firefox\firefox.exe"
    For /F "tokens=*" %%# in ('"Dir /b "%Folder%\*.url""') Do (
    PowerShell [System.IO.File]::ReadLines^('"%Folder%\%%#"'^)^|^
    %%{If^($_ -match 'URL='^){$URL=$_ -replace 'URL=','';Start '"%Browser%"' $URL}})
    Make sure the highlighted paths, i.e. the folder and browser, are correct.
    Last edited by Matthew Wai; 10 Apr 2022 at 08:42.
      My Computer


  7. Posts : 108
    Windows 7 and 10
    Thread Starter
       #7

    Matthew, thank you for that suggestion. Unfortunately, it did not seem to do anything. I tried this modification:

    Code:
    set "Folder=W:\URLs"
    for /F "tokens=*" %%# in ('"dir /b "%Folder%\*.url"') do (
      PowerShell [System.IO.File]::ReadLines^('"%Folder%\%%#"'^)^|^
      %%{if^($_ -match 'URL='^){$URL=$_ -replace 'URL=','';start Firefox.lnk $URL}}
    )
    I deleted @echo off, at least for the moment, so I could see what was happening. I simplified the reference to Firefox by citing Firefox.lnk, which exists in C:\Windows. I thought I detected a miscount on quotation marks in the for line, so I corrected (if that's the right word) those, so now they match.

    I try to avoid PowerShell because, like a good woman, it can do a lot, but most of the time I really have no idea exactly what it is doing, much less how it will all turn out.

    Despite these precautions, in batch scripting and also in life, I still find that nothing really works. Open to further ideas. In both spheres.
      My Computer


  8. Posts : 7,607
    Windows 10 Home 20H2
       #8

    raywood said:
    Code:
    set "Folder=W:\URLs"
    for /F "tokens=*" %%# in ('"dir /b "%Folder%\*.url"') do (
      PowerShell [System.IO.File]::ReadLines^('"%Folder%\%%#"'^)^|^
      %%{if^($_ -match 'URL='^){$URL=$_ -replace 'URL=','';start Firefox.lnk $URL}}
    )
    The path of Firefox is missing from your above code.
    Please run the batch script attached below and post the output.

    👉 Visit_the_URLs - testing.bat

    raywood said:
    I simplified the reference to Firefox by citing Firefox.lnk
    You have to use the full path.

    raywood said:
    I try to avoid PowerShell because, like a good woman, it can do a lot, but most of the time I really have no idea exactly what it is doing, much less how it will all turn out.
    I can explain what it is doing if you are interested to know.
    Batch File to Execute All Files (or at least all URLs) in a Folder Attached Files
      My Computer


  9. Posts : 2,799
    Linux Mint 20.1 Win10Prox64
       #9

    Opening the URL link file name as a parameter to firefox will not work. Need to open the URL link inside the file

    [InternetShortcut]
    URL=https://www.youtube.com/

    The short scripts will work with whatever your default browser is. Not restricted to Firefox.

    Batch:
    Code:
    @echo off
    set URL="J:\_PowerShell\URLLinks"
    for /f "tokens=2 delims=^=^(" %%a in ('type %URL%\*.url 2^>nul ^| find "URL=http"') do start %%a ; exit
    Powershell:
    Code:
    $URL= "J:\_PowerShell\URLLinks"  # Replace Files path
    cat $URL\*.url  | % { if($_ -match "URL=") { saps $_.replace("URL=", "") }};exit
    Below is the attachment for both, unzip to the same folder, including 3 url shortcuts as example. Right click on the power shell script and click on "Run with Powershell" or just copy and paste to Powershell windows. Double click on the bat file to run. Both will give same result.

    MultipleLinks.zip

    NOTE: To run the powershell script. You'd need to run one time: set-executionpolicy bypass first with Admin powershell.
    Last edited by topgundcp; 12 Apr 2022 at 06:23.
      My Computer


  10. Posts : 108
    Windows 7 and 10
    Thread Starter
       #10

    Many thanks for the replies. Yes, I am often this slow to realize that someone has been talking to me.

    To refine something I said earlier, my problem with PowerShell (in my limited attempts to date) is that it seems one must master it before one can use it, because it has so many exceptions to everything. Not sure that's fair; that's just a working impression. So batch it is, at least for me, at least for now.

    I tried topgundcp's batch suggestion. It works. It's exactly what the doctor ordered: I drag URLs from the browser to the specified folder; I run the batch file; and those URLs open in separate tabs in Firefox.

    It works even though some kind of Windows bug is preventing me from opening those URLs in that folder by double-clicking on them.

    Problem solved. Notable improvement in functionality. Many thanks!
      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 03:52.
Find Us




Windows 10 Forums