PCbanter

PCbanter (http://www.pcbanter.net/index.php)
-   General XP issues or comments (http://www.pcbanter.net/forumdisplay.php?f=18)
-   -   cmd.exe - using exclamation mark with delayed variable expansion (http://www.pcbanter.net/showthread.php?t=760297)

Piotr March 30th 05 01:19 PM

cmd.exe - using exclamation mark with delayed variable expansion
 
Hi,

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

Regards,

Piotr

David Candy March 30th 05 01:31 PM

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

--=20
----------------------------------------------------------

"Piotr" wrote in message =
...
Hi,
=20
I've enabled "delayed environment variable expansion". How can I use =

an=20
exclamaton mark in filenames in my batch files?
=20
Regards,
=20
Piotr


Piotr March 30th 05 01:49 PM

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

Pegasus \(MVP\) March 30th 05 02:00 PM


"Piotr" wrote in message
...
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"
)



David Candy March 30th 05 02:02 PM

Use ! instead of %

--=20
----------------------------------------------------------

"Piotr" wrote in message =
...
Uhh? Why do you want to? Use ! instead of %.

=20
I need delayed environment variable expansion.
=20
And I want to use cmd.exe not bash :)))
=20
Regards,
=20
Piotr


Piotr March 30th 05 02:19 PM

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

Pegasus \(MVP\) March 30th 05 02:25 PM


"Piotr" wrote in message
...
Trial and error shows that this works:


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.



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




Piotr March 30th 05 02:31 PM

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

David Candy March 30th 05 02:36 PM

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

--=20
----------------------------------------------------------

"Piotr" wrote in message =
...
Use ! instead of %

=20
Either I don't understand what you mean, or you don't understand me. =

Maybe=20
both :)
=20
But Pegasus (MVP) gave me an answer.
=20
The problem is - I run cmd.exe with "delayed environment variable =

expansion"=20
(DEVE). And I need to use files/directories with an exclamation mark =

in=20
theirs names. For example:
=20
@echo off
mkdir !info
dir Z:\ /s /b !info/!CD.txt
=20
And don't ask me why I need DEVE :)
=20
Regards,
=20
Piotr


Piotr March 30th 05 02:37 PM

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

Pegasus \(MVP\) March 30th 05 02:52 PM


"Piotr" wrote in message
...
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


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.



Piotr March 31st 05 07:21 AM

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


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


Piotr March 31st 05 07:35 AM

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


All times are GMT +1. The time now is 07:22 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2006 PCbanter
Comments are property of their posters