Solved How to replace exclamation in filenames using batch?

January 29, 2014 at 13:11:56
Specs: Windows 7
Im using a batch file to copy 100s of files. . Eg:

Here's 2 lines from my batch file:

a:
copy "c:\%vare1%"

Problem is because the variable
%vare1% is the filename "windows!!.txt" and has an exclamation in it, cmd misreads it as "windows .txt" thus giving the message thast the file was not found.

I get the same problem with renaming or moving filenames with an exclamation in a batch file. Any way to fix this?


See More: How to replace exclamation in filenames using batch?

Report •


#1
January 29, 2014 at 19:45:33
✔ Best Answer
Might try this, set first line of your batchscript as:
setlocal disabledelayedexpansion

But if your batch uses "!" for access to non-delayed var.s, then you'll have to re-work the script to use subroutines, because "!" is no longer in effect for enabled expansion.


Report •
Related Solutions


Ask Question