Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Open an file using a batch file ?

Options
  • 08-12-2005 2:42am
    #1
    Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,692 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 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: 91,692 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 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: 91,692 Mod ✭✭✭✭Capt'n Midnight


    Thanks, some useful bits there.


Advertisement