• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Help with variables

#1
I did a lot with 4DOS about 20 years ago, but only lately tried to use TCC, and just can't get it anymore.

For example, take a file named "test sub.txt". If I execute from the command line, echo %@filedate["test sub.txt",w,4], I get the date I want in the expected format. But not if I set f="test sub.txt" and try to echo %@filedate[%f,w,4] or %@filedate["%f",w,4]. No matter what I do I get "The system cannot find the file specified."

What am I missing?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,496
45
Albuquerque, NM
prospero.unm.edu
#2
I did a lot with 4DOS about 20 years ago, but only lately tried to use TCC, and just can't get it anymore.

For example, take a file named "test sub.txt". If I execute from the command line, echo %@filedate["test sub.txt",w,4], I get the date I want in the expected format. But not if I set f="%1" and try to echo %@filedate[%f,w,4] or %@filedate["%f",w,4]. No matter what I do I get "The system cannot find the file specified."
%1 is an argument to a batch file, right? And batch file arguments are split at word boundaries; so %1 will only hold a string containing spaces (like, say, TEST SUB.TXT ) if you pass it to the batch file in quotes:

Code:
mybatch.btm "test sub.txt"
But in that case it'll already have the double quotes; you don't need to add any more.

Code:
@echo off
rem  mybatch.btm
set f=%1
echo %@filedate[%f,w,4]
or, more simply:

Code:
@echo off
rem  mybatch.btm
echo %@filedate[%1,w,4]
 
#3
... But in that case it'll already have the double quotes; you don't need to add any more.

Code:
@echo off
rem  mybatch.btm
set f=%1
echo [EMAIL="%@filedate"]%@filedate[/EMAIL][%f,w,4]
 
Thanks, Charles Dye, for your clear example. But am I embarrassed. 
 
When my much longer btm file didn't work I ran various little tests. One of them looks exactly like your example. So I ran yours anyway. Naturally it worked. I ran mine again. It failed! Weird? Yeah, because mine has "%l" where yours has "%1" in a font where they look the same. Without seeing your clean example I would NEVER have found it!
 
However, I'm still confused about the quotes.
 
Say that echoing %1 gives me "word1 word2", and echoing %G gives me "word3 word4 word5". Then, ren %1 %G works, but I don't see why. 
 
I would think it should be, ren "%1" "%f'", which fails. But without the quotes, wouldn't it look to the parser like, ren word1 word2 word3 word4 word5?
 
Unless the quotes are part of the strings in the string variables, but that can't be, can it?
 
I am definitely confused.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,496
45
Albuquerque, NM
prospero.unm.edu
#4
However, I'm still confused about the quotes.

Say that echoing %1 gives me "word1 word2", and echoing %G gives me "word3 word4 word5". Then, ren %1 %G works, but I don't see why.

I would think it should be, ren "%1" "%f'", which fails. But without the quotes, wouldn't it look to the parser like, ren word1 word2 word3 word4 word5?

Unless the quotes are part of the strings in the string variables, but that can't be, can it?

I am definitely confused.
Yes, the double quotes are stored in the variable. The parser won't remove them automatically. (Backquotes, on the other hand, are stripped off automatically before the command is executed....)

Here's another batch you can play with. Try passing it different sets of arguments, with and without spaces, in double quotes or backquotes, or no quotes at all.

Code:
@echo off
rem  //  argtest.btm

iff %# == 0 then
   echo No arguments!
else
   for /l %i in ( 1,1,%# ) echo %%%i is %[%i]
endiff
 
#5
Code:
@echo off
rem  //  argtest.btm
 
iff %# == 0 then
   echo No arguments!
else
   for /l %i in ( 1,1,%# ) echo %%%i is %[%i]
endiff
I really appreciate the little batch program. Very helpful in unscrambling my brains. [Somewhere in the course of emacs, Lisp, Snowbal, Perl, C++ and for the last ten years Basic (ugh!) I think they've been run through a food processor.]
Thanks,
Mike Suman
 
Top Bottom