I have a batch file where a user enters a path to a file and I extract the filename form that path.
I use that filename to create a folder of the same name.
In that folder, I want to create a log.txt file that the process I am calling in my batch file can write its log messages to.
Here's the code:
set /p pathFoFile="Enter path fo file: "
FOR %%i IN ("%pathFoFile%") DO (
set outputFolder=%%~ni
)
someprocess -p1 blabla -p2 blabla -p3 %outputFolder% > %outputFolder%\log.txt
The last part, %outputFolder%\log.txt, seems to be the problem, since it works when I just put > log.txt
However, when I echo this:
echo %outputFolder%\log.txt
it prints the correct path.
How can I use the foldername and create this log.txt file?
EDIT
The path I get may look like this:
..\some\folder\thefile.egf
or just
thefile.egf
or an absolute path.
I extract the
thefile
and would like to call:
someprocess -p1 blabla -p2 blabla -p3 thefile > thefile\log.txt
the folder thefile containing log.txt should be created relative to the batch file. There are no drive letters in the path.
The error I get when using %outputFolder%\log.txt or "%outputFolder%\log.txt" is that the system cannot find the path.
dirinstead ofsomeprocessand it worked fine. Does the path you typed include the drive letter and no trailing slash?mkdir "%outputFolder%"before redirecting like> "%outputFolder%\log.txt". (Put quotes around all paths to avoid trouble with potential white-spaces or special characters.)