How to use filenames with "!" in an expanded variable?

S

ShadowTek

If I use the following in a batch file, then a file named "hi!" will
be echoed as "hi".

setlocal EnableDelayedExpansion
for %%G in (Input_Files\*) do (
echo %%G
)

This breaks proper file referencing when trying to work with anything
that has an exclamation point in it.

Is it just not possible to use any files with "!" when delayed
expansion is enabled? Or is there still some way to work with it?
 
P

Pegasus \(MVP\)

ShadowTek said:
If I use the following in a batch file, then a file named "hi!" will
be echoed as "hi".

setlocal EnableDelayedExpansion
for %%G in (Input_Files\*) do (
echo %%G
)

This breaks proper file referencing when trying to work with anything
that has an exclamation point in it.

Is it just not possible to use any files with "!" when delayed
expansion is enabled? Or is there still some way to work with it?

The exclamation mark takes the place of % when using
EnableDelayedExpansion and becomes therefore one of
the dreaded "poison" characters. Working with them gets
very messy if not impossible. I suggest you repost your question
in alt.msdos.batch.nt - they love this sort of challenge.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top