Jump to content

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


Recommended Posts

Guest ShadowTek
Posted

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?

  • Replies 2
  • Created
  • Last Reply

Popular Days

Guest Pegasus \(MVP\)
Posted

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

 

 

"ShadowTek" <psistormyamato@cs.com> wrote in message

news:649a2e19-137f-44bd-87c2-0e03d3aa0a28@2g2000hsn.googlegroups.com...

> 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.

Guest ShadowTek
Posted

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

 

On Jun 10, 1:15 am, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

>I suggest you repost your question

> in alt.msdos.batch.nt - they love this sort of challenge.

 

Ok, thanks.


×
×
  • Create New...