cmd.exe - using exclamation mark with delayed variable expansion

G

Guest

Hi,

I've enabled "delayed environment variable expansion". How can I use an
exclamaton mark in filenames in my batch files?

Regards,

Piotr
 
G

Guest

Uhh? Why do you want to? Use ! instead of %.

I need delayed environment variable expansion.

And I want to use cmd.exe not bash :)))

Regards,

Piotr
 
P

Pegasus \(MVP\)

Piotr said:
Hi,

I've enabled "delayed environment variable expansion". How can I use an
exclamaton mark in filenames in my batch files?

Regards,

Piotr

Trial and error shows that this works:

@echo off
echo. > !b!.txt
setlocal enabledelayedexpansion
for /L %%a in (1,1,9) do (
set b=%%a
echo a=%%a, b=!b!
dir /b "^!b^!.txt"
)
 
G

Guest

Trial and error shows that this works:

Why not manual??? :)
dir /b "^!b^!.txt"

Thanks. It works. I've not imagined that there had to be *both* quotations
marks and ^ (eg "^!")...

Thanks once again

Piotr
 
P

Pegasus \(MVP\)

Piotr said:
Why not manual??? :)

Because batch file language is not a nice and tightly defined
programming language. It's full of little and unexpected
surprises, and as many frustrations and disappointments.
 
G

Guest

Use ! instead of %

Either I don't understand what you mean, or you don't understand me. Maybe
both :)

But Pegasus (MVP) gave me an answer.

The problem is - I run cmd.exe with "delayed environment variable expansion"
(DEVE). And I need to use files/directories with an exclamation mark in
theirs names. For example:

@echo off
mkdir !info
dir Z:\ /s /b > !info/!CD.txt

And don't ask me why I need DEVE :)

Regards,

Piotr
 
D

David Candy

It sounds like your problem was quoting filenames. You would have had the same problem with %. So your question had nothing to do with DEVE. So don't waste people's time here with delibrate misinformatrion wanker.
 
G

Guest

Why not manual??? :)
Because batch file language is not a nice and tightly defined
programming language. It's full of little and unexpected
surprises, and as many frustrations and disappointments.

But since Microsoft is still making changes to it maybe there is a future :)
Why do I have to use VBS just to make some backups, compress some files and
so on. I'm using batches for 15 years and I like them :)))

Piotr
 
P

Pegasus \(MVP\)

Piotr said:
But since Microsoft is still making changes to it maybe there is a future :)
Why do I have to use VBS just to make some backups, compress some files and
so on. I'm using batches for 15 years and I like them :)))

Piotr

I did not say that you have to use VBS. I only replied
to your question about the documentation for this
particular syntax. There isn't any, and I don't think
there will ever be. If you wish to do something special
in a batch file, try it. If it works - great!, but don't expect
it to be as robust as in a programming language. I don't
think, for example, that anyone has ever tried to explain
why the "call" command is necessary in the following sample
code, and why it works, but it does!

@echo off
set variable=abcdefg
set string1=cde
set string2=xyz
call set variable=%%variable:%string1%=%string2%%%
echo Var=%variable%

Now consider how string substitution is done in a
programming language, then shake your head in amazement
about this extraordinary piece of code.
 
G

Guest

It sounds like your problem was quoting filenames. You would
have had the same problem with %. So your question had
nothing to do with DEVE. So don't waste people's time here
with delibrate misinformatrion wanker.

LOL... Really...

No, my problem wasn't quoting filenames (why I had to put ^ before ! *and*
had to quote it?)

No, I wouldn't have had the same problem with % - I just place two %% which
is translated to one %... (it was working for ages - since DOS 3.30 fore sure
:)

Yes, my question *does* have something with DEVE - my batches stopped
working just after I had turned on DEVE... Why? Bad current voltage? :)))

No, I do *not* waste people's time. Do you?

Regards

Piotr
 
G

Guest

OK, you are right. Batch file language *is* full of bugs, I mean *features*
:))))

Maybe call makes cmd to run subshell? I've never tried to use call but to
run another batch file... Wow :)))

Piotr
 

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