I'm writing a script that needs need to call a parameter from an executable's initialization file. I know where the executable is in this instance, but I'd like to write a reusable subroutine as I see this as a potential helpful tool. What I am after specifically would be the following:
Program 1.exe has a parameter file located at:
c:\a\b\c d e\f\g.ini
Program 2.exe similarly has one located at:
c:\a\b\c d e\256\here_there\initialize.xml
I'd like to have the subroutine work as follows:
:: extract.bat
@echo off
:GetTarget from user input
set FILEPATH="c:\a\b\c d e\f.txt"
if not (%1)==() set FILEPATH=%1
REM where FILEPATH is a path to a file, whether fully qualified
REM or relative doesn't matter, we'll parse the string and
REM make it fully qualified and even set environmental
REM variables as needed.
:CheckExist make sure the expanded %FILEPATH% exists
echo. Checking to see if %FILEPATH% exists...
echo.
if not exist %FILEPATH% (echo.%FILEPATH% does not exist or is not a valid file name.
goto :EOF
)
echo. %FILEPATH% exists.
echo.
:EXPAND FILEPATH to parse
if "FILEPATH"=="" goto :JUMPOUT
for /f "tokens=1* delims=\" %%a in ("%FILEPATH%") do (
echo. %%a
set FILEPATH=%%b
goto :EXPAND
)
:JUMPOUT
:EOF
Here's where I get a little confused. I guess I need to echo the output to a temp file in %TMP% so I can use the find command, but there has to be an easier way to parse the result.
Finding the drive should be easy since we can search on a ':' and the letter prior is the drive.
Finding the file name should be easy as it will be the last output. However, I don't want to use a FIND command here because the file may or may not have an extension.
The rest of the path should be easy as we can just construct the directories as the variables in between.
set path=%dir1%%dir2%%dir3%...%dir*%
However, getting each of these above output lines into a variable is where I am a little fuzzy.
Also, I want to be able to check the path of the extract.bat file itself and test to see if the string provided in the input is a fully qualified path or a relative path to the current directory, and then regardless of the input construct a fully qualified path as a possible output to pass to another subroutine.
Any advice or hints or input on this script would be greatly appreciated.