Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#16
Post
by Ed Dyreen » 17 Mar 2012 16:35
'
Still don't get it
why does
Code: Select all
del "dummy.txt" 2>nul
for %%a in ("dummy.txt") do echo %%~aa
expands to
Code: Select all
>del "dummy.txt" 2>nul
>for %a in ("dummy.txt") do echo %~aa
>echo
ECHO is on (aan).
while it should expand to
Code: Select all
>del "dummy.txt" 2>nul
>for %a in ("dummy.txt") do echo %~aa
>echo a
a
?
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#17
Post
by Ed Dyreen » 17 Mar 2012 16:38
'
Now it make sense
Code: Select all
del "dummy.txt" 2>nul
for %%? in ("dummy.txt") do echo %%~a?
This however never fails
Code: Select all
del "dummy.txt" 2>nul
for %%? in ("dummy.txt") do echo %%~??
for %%? in ("dummy.txt") do echo %%~?a
Haha, Now I remember why I don't like alpha-numeric and now we can start this discussion all over again

Thanx !
-
aGerman
- Expert
- Posts: 4716
- Joined: 22 Jan 2010 18:01
- Location: Germany
#18
Post
by aGerman » 17 Mar 2012 17:33
Actually there is no need to discuss which is better. Both have pros and cons. The main thing is you'll take the right decision in the right case, isn't it
Regards
aGerman
(BTW I've just noticed that we're totally off topic in this thread

)
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#19
Post
by foxidrive » 18 Mar 2012 06:34
aGerman wrote:Alpha characters have also side effects. For that reason it's really nothing but a question of the style one would prefer.
Code: Select all
@echo off &setlocal
del "dummy.txt" 2>nul
for %%a in ("dummy.txt") do echo %%~aa
for %%A in ("dummy.txt") do echo %%~Aa
for %%A in ("dummy.txt") do echo %%~AA
>>"dummy.txt" type nul
for %%a in ("dummy.txt") do echo %%~aa
for %%A in ("dummy.txt") do echo %%~Aa
for %%A in ("dummy.txt") do echo %%~AA
pause
You are misusing the commands above, and also have case sensitive issues. It's got nothing to do with alpha metavariables.
Here is a sample with the case sensitive issues removed.
Code: Select all
@echo off &setlocal
del "dummy.txt" 2>nul
for %%a in ("dummy.txt") do echo %%~aa
for %%a in ("dummy.txt") do echo %%~Aa
for %%a in ("dummy.txt") do echo %%~Aa
>>"dummy.txt" type nul
for %%a in ("dummy.txt") do echo %%~aa
for %%a in ("dummy.txt") do echo %%~Aa
for %%a in ("dummy.txt") do echo %%~Aa
del "dummy.txt" 2>nul
for %%A in ("dummy.txt") do echo %%~aA
for %%A in ("dummy.txt") do echo %%~AA
for %%A in ("dummy.txt") do echo %%~AA
>>"dummy.txt" type nul
for %%A in ("dummy.txt") do echo %%~aA
for %%A in ("dummy.txt") do echo %%~AA
for %%A in ("dummy.txt") do echo %%~AA
pause
-
aGerman
- Expert
- Posts: 4716
- Joined: 22 Jan 2010 18:01
- Location: Germany
#20
Post
by aGerman » 18 Mar 2012 12:20
foxidrive wrote:You are misusing the commands above, and also have case sensitive issues.
I'm aware of that. But as you can see it has a big potential for misunderständings

Regards
aGerman
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#21
Post
by foxidrive » 18 Mar 2012 20:53
aGerman wrote:foxidrive wrote:You are misusing the commands above, and also have case sensitive issues.
I'm aware of that. But as you can see it has a big potential for misunderständings

Regards
aGerman
hehe Syntax confusion? Welcome to batch files 101.