A Windows XP help forum. PCbanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » PCbanter forum » Microsoft Windows XP » General XP issues or comments
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

cmd.exe - using exclamation mark with delayed variable expansion



 
 
Thread Tools Display Modes
  #1  
Old March 30th 05, 01:19 PM
Piotr
external usenet poster
 
Posts: n/a
Default 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
Ads
  #2  
Old March 30th 05, 01:31 PM
David Candy
external usenet poster
 
Posts: n/a
Default

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

  #3  
Old March 30th 05, 01:49 PM
Piotr
external usenet poster
 
Posts: n/a
Default

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
  #4  
Old March 30th 05, 02:00 PM
Pegasus \(MVP\)
external usenet poster
 
Posts: n/a
Default


"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"
)


  #5  
Old March 30th 05, 02:02 PM
David Candy
external usenet poster
 
Posts: n/a
Default

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

  #6  
Old March 30th 05, 02:19 PM
Piotr
external usenet poster
 
Posts: n/a
Default

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
  #7  
Old March 30th 05, 02:25 PM
Pegasus \(MVP\)
external usenet poster
 
Posts: n/a
Default


"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



  #8  
Old March 30th 05, 02:31 PM
Piotr
external usenet poster
 
Posts: n/a
Default

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
  #9  
Old March 30th 05, 02:36 PM
David Candy
external usenet poster
 
Posts: n/a
Default

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

  #10  
Old March 30th 05, 02:37 PM
Piotr
external usenet poster
 
Posts: n/a
Default

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
  #11  
Old March 30th 05, 02:52 PM
Pegasus \(MVP\)
external usenet poster
 
Posts: n/a
Default


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


  #12  
Old March 31st 05, 07:21 AM
Piotr
external usenet poster
 
Posts: n/a
Default

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

  #13  
Old March 31st 05, 07:35 AM
Piotr
external usenet poster
 
Posts: n/a
Default

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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exclamation mark Barbara General XP issues or comments 7 February 12th 05 10:06 PM






All times are GMT +1. The time now is 09:43 AM.


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