I have following script to list out all the files, recursively from a directory, having a .phtml
extension.
@echo off
setlocal
for /f %%G in ('forfiles /s /m *.phtml /c "cmd /c echo @relpath"') do echo %%G >> listoffiles.txt
endlocal
exit
It lists out only relative path to files. The above script is running from an intermediate location, so I am not getting full paths in @relpath
variable.
Also I am getting quotes in the result lines, which I want to remove.
I want to get absolute path to those files with a few code changes as possible, if a global-variable is available which can be used in my code then it's best for me, as I am not much of Windows batch scripter.
Best Answer
I am not getting full paths in the
@relpath
variable.The following batch file does what you want:
Notes:
@path
(Full path of the file) instead of@relpath
(Relative path of the file).substring
expression to remove the quotes (:~1,-1
removes the first and last characters from the variable string).setlocal EnableDelayedExpansion
so that variables are updated correctly in thefor
loop.Further Reading