I am writing a simple batch script to get the filenames in a folder and write the output to a file. At the same time, I am appending a string to the file.
@echo off
set $string=!source ./
set "loc=C:\path\to\dir\files\scripts\"
pushd %loc%
(for %%a in (*) do (
echo %$string%%%~dpnxa))>output.txt
popd
output.txt:
!source ./C:\path\to\dir\files\scripts\abc.txt
!source ./C:\path\to\dir\files\scripts\xyz.txt
I am having a hard time replacing backslash \ with forward-slash / in the output and also removing this part C:\path\to\dir\files\ from the path.
In the end, I am trying to achieve something like this written to a file:
final_output.txt:
!source ./scripts/abc.txt
!source ./scripts/xyz.txt
Any help will be great.
%%~dpnxa(which is equivalent to%%~fa) returns full paths, but I think you want%%~nxato return pure file names. To get the parent namescriptsyou could do this:for %%a in (*) do for %%b in ("%%~dpa.") do echo(%$string%%%~nxb/%%~nxa…