Solved How to get rid of ) in a filename using batch?

February 17, 2014 at 18:18:13
Specs: Windows 7
I have 100s of filenames with an end bracket in them. i.e : ")"
My batch crashes everytime a filename with an end bracket ) in its name gets used. I assume its because of the code below:

FOR /F "usebackq" %%A IN ('%vare1%') DO set svare1=%%~zA

I need to be able use the above code to determine the size of a file, so I was wondering if there's a way to automatically get the ) replaced in a filename through a batch.

From this site Ive learned there are 2 ways to replace letters in the name of a filename . Unfortunately, both codes are unable to get rid of the ) in a filename when I tried to replace them with "aaaa"

Code 1:
FOR %%a IN (*.jpg) DO (
SET Var=%%~na
CALL SET Var=%%Var:)=aaaa%%
CALL REN "%%a" "%%Var%%.jpg"
Code 2:

FOR /f "tokens=*" %%a IN ('DIR /b "*.jpg"') DO (
SET Var=%%~na
SET Var=!Var:)=aaaa!
REN "%%a" "!Var!.jpg"

Thanks again for your knowledge

See More: How to get rid of ) in a filename using batch?

Report •

February 18, 2014 at 10:53:51
✔ Best Answer
SET Var=!Var:^)=aaaa!

instead of
SET Var=!Var:)=aaaa!

see if that works better. not tested on your system, recommend to do so.


message edited by mikelinus

Report •

February 18, 2014 at 21:22:44
I didn't encounter a problem on XP (which included a end-arenthesis filename):
for %%a in (*.*) do set v=%%~nxa %%~za & set v & pause

Maybe if Mike's suggestion doesn't work, you could post more of your code to show context and application.

Report •

February 19, 2014 at 04:11:43
To be honest nbrane, I didn't actually check it without the escape. I just presumed that was the issue, I only tested it with one file as well "test).jpg". Probably a good point.


Report •

Related Solutions

Ask Question