Simple question about "Function" command...

May 24, 2010
855
0
Northlake, Il
Please excuse me if this is a set of stupid questions; I'm rather fond of stupid questions at this point in my life. So, here is a "sample" function definition (purely for illustration purpose; it's not the final version of the function that I'm actually trying to write):

Function Sample=`@Eval[@FileSize[%2 %1,b,%3]/@Files[%2 %1]]`
And here's the "results" of invoking said function:

[Z:\]echo %@Sample[*.txt]
@Eval[@FileSize[ *.txt,b,]/@Files[ *.txt]]

[Z:\]echo %@Sample[*.txt,/S]
@Eval[@FileSize[/S *.txt,b,]/@Files[/S *.txt]]

[Z:\]echo %@Sample[*.txt,/S,a]
@Eval[@FileSize[/S *.txt,b,a]/@Files[/S *.txt]]

[Z:\]echo %@Sample[*.txt,,a]
@Eval[@FileSize[ *.txt,b,a]/@Files[ *.txt]]

Exactly what I would hope for.

So here's function definition in the "attempt" to make the function more "real":

Function Sample=`@Eval[%@FileSize[%2 %1,b,%3]/%@Files[%2 %1]]`

And here's the "results" of trying to invoking the above function:

[Z:\]echo %@Sample[*.txt,/S]
@Eval[21547243/186]

[Z:\]echo %@Sample[*.txt]
@Eval[21546573/185]

[Z:\]echo %@Sample[*.txt,/S]
@Eval[21547243/186]

[Z:\]echo %@Sample[*.txt,/S,a]
@Eval[22085632/186]

[Z:\]echo %@Sample[*.txt,,a]
@Eval[-1/0]

[Z:\]echo %@Sample[*.txt,``,a]
@Eval[-1/0]

Not exactly what I would expect. And, more importantly, incorrect!!!

So, the questions are, of course, what is going on here and what am I doing wrong and how do I fix it?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,461
88
Albuquerque, NM
prospero.unm.edu
It looks to me like you have no *.TXT files in the current directory. @FILESIZE therefore returns -1, and @FILES returns 0.

Doing this correctly would be pretty tricky in a user-defined function. You would need to check for the no-matching-files condition before doing the division.
 
May 24, 2010
855
0
Northlake, Il
Charles, it was a good guess, but it is, simply put, flat-out not the case.

Specifically:

[Z:\]Echo %@Files[*.txt]
185

And, just for the record:

[Z:\]echo %@Files[*]
380

(I forgot to mention getting very similar results with the "all" pattern ("*" of course)).

And I'll note there is only a problem when the second argument is not present and the third one argument is, i.e., "Echo %@Sample[*.txt,,]" works fine yielding "@Eval[21546573/185]", whereas "Echo %@Sample[*.txt,,a]" yeilds "@Eval[-1/0]" (which was clearly shown in the second sequence above that ends in "echo %@Sample[*.txt,``,a]" - one of the "failures").

- Dan


But thank you.

- Dan
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,461
88
Albuquerque, NM
prospero.unm.edu
Okay, I actually tried it. I get different results from you in the first test:


C:\Bin\Words>Function Sample=`@Eval[@FileSize[%2 %1,b,%3]/@Files[%2 %1]]`

C:\Bin\Words>echo %@sample[*.txt,,a]
@Eval[@FileSize[a *.txt,b,]/@Files[a *.txt]]

C:\Bin\Words>option

C:\Bin\Words>


It seems that, for me at least, TCC is completely ignoring the second, empty, argument, and assigning the third argument to %2.
 
May 24, 2010
855
0
Northlake, Il
Charles, what you get is what I expected to get (my dim recollection is that TCC functions do not "accept" null arguments), but, as you can see, it isn't what I did get. However, after thinking about it for a while and "reworking" the function a bit to use "%@UnQuote[%2]" instead of just "%2", and supplying an otherwise empty double-quoted string as the second argument (i.e., %@Sample[*.txt,"",a]) everything now works fine, and it's only slightly inconvenient (if I remember it, of course!!! ; > ) >.

But thank you again.

- Dan
 
Similar threads
Thread starter Title Forum Replies Date
M Maybe Maybe I'm being stupid (again), but a simple question... Support 4
M How to? A very simple question re. the current line number in a batch file... Support 2
C Simple .bat question - dump contents of 2 dimensional array Support 2
M Another simple question re. Take Command/TCC window witdth in characters... Support 16
M A simple question related to the "dir" (and "pdir") commands... Support 5
P "Simple question" concerning insert/overstrike mode Support 17
samintz How to? TPIPE /simple=61 Support 6
GermanDirk How to? EVENTLOG Command with simple User Rights not functional Support 4
H TPIPE /simple=4 Support 12
T How can I send a simple parameter to a script, in tc 25? Support 2
C No simple way to tell new Alerts Support 8
P Simple RegEx copy Support 9
C WAD tpipe /simple=28 Support 8
C tpipe /simple=28 error Support 5
P WAD TC 15.0.1.58 x64 crasches with a simple dir command Support 18
M What am I doing wrong in this (very simple!) code? Support 3
D Some feedback on simple batch file Support 2
C forum Posting Question... Support 3
C question re: Move Support 3
S How to? Upgrade Question: What supporting documentation is required at time of purchase? Support 2
Peter Murschall Documentation Question to %@PSHELL Support 4
Fross Tab Question Support 6
Fross Quick Function Question Support 17
Dick Johnson Question about the Touch command Support 0
rps Documentation "Copy+Paste+run" question Support 2
vefatica SFTP question Support 17
vefatica Question about IPWorks Support 0
C How to? SHORTCUT question..... Support 6
vefatica TPIPE, crash and question Support 1
C Question / Suggestion Support 1
MickeyF Another TPIPE question Support 6
vefatica Another @EVERYTHING question Support 4
mikea How to? %@everything[] question Support 10
A License Question for Single User Support 5
Jay Sage Help Correction (and Related Question) Support 0
S Elapsed time in TCC prompt question Support 0
H command line parsing question Support 5
C Forum question Support 2
B Newbie here, I have a question. Support 4
J Dumb Question ... Support 4
Timothy Byrd Updating from TC 9 to TC 17 - TCTOOLBAR question Support 2
M A possibly stupid question about the "del" command... Support 7
M A just out of curiosity question re @DiskTotal Support 4
Fross Status Bar Time Question Support 1
A Stupid, obvious question - launch a BAT with TC Support 10
C How to? GLOBAL question Support 5
vefatica OT: VisualStudio question Support 1
vefatica Wildcard question Support 4
Dan Glynhampton v15 installer question Support 2
C Move question with Encrypted file... Support 6

Similar threads