Thursday, August 17, 2017

batch - For loop where the for variable contains parenthesis

I have a number of files that contain a line that needs to be deleted. These files are contained in subdirectories of a specific directory, and all files of a specific extension need to be iterated through and the line deleted. The problem I have is that the path has brackets and spaces, which seem to prevent the loop from working properly. How do you escape the path?


The code I have currently:


For /R "%ALL_BUT_FIRST%\bin\%1\Scripts" %%G in (*.csx) do (
echo %%G
findstr /V "texttoreplace" "%%G" >"%%G"
)

When not trying to write to the file, findstr outputs to the console the correct result perfectly. It is only writing the file that causes the .bat to fail with the error:


C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5185,5): error MSB3073: The command ""D:\Users[username]\Desktop\Other projects (ie open source ones)\Freee\FrEee.WinForms\post-build.bat" Debug D:\Users[username]\Desktop\Other projects (ie open source ones)\Freee\FrEee.WinForms\" exited with code 1.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...