Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Open an file using a batch file ?

  • 08-12-2005 02:42AM
    #1
    Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 96,135 Mod ✭✭✭✭


    Similar to the webpage thread, I want to open ANY file from a batch file. By file I mean what Windows 3 used to call documents - registered file types [minirant]that was so handy on Windows 3 docs separate from other files [/minirant]

    In order to save space on duplicate files I'm creating a single instance store and having "file name.bat" as a pointer to the original copy of the "file name". So if you click on the batch it opens the original file. Also means you can search for "file name" etc.

    Start "file name" usually works and I'd like to do it this way because I could then replace multiple "file name" with "file name.bat" so it keeps going through batch files until it finds a real file.
    But a lot of the time it opens a new command prompt window..

    Explorer.exe "file name" kinds works but it won't call "file name.bat" if "file name" isn't found, but I could tweak the batch files to do that themselves.

    Is there a general technique to do this - I'd like to avoid WSH if possible


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Are you trying to start batch files? If so you should be using CALL instead. You could probably set up an IF statement in the batch file to determine if it is a batch file and use CALL instead of START.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 96,135 Mod ✭✭✭✭Capt'n Midnight


    I don't want to use call as there might be nested ones.
    Then again I can use EXIT as well.

    Looks like IF EXIST will get used a lot

    If else fails then I'll start an explorer window from the containing folder - but messy since will have to CD N times


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Still not entirely sure what you are trying to do?

    You wouldn't need to nest IF statements if your using CMD as it allows you more control.

    For starters you can do something like

    for %X in (*.*) do echo %xX

    This will find all files and print out the extension.

    So you could do something like...
    for %%Z in (*.*) do call :exec %%~xZ %%Z
    goto end
    
    :exec
    if /I %1. == .bat. goto runBat
    shell %2
    goto end
    
    :runBat
    call %2
    goto end
    
    :end
    


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 96,135 Mod ✭✭✭✭Capt'n Midnight


    Thanks, some useful bits there.


Advertisement