#60962 - 2001-12-03 03:44 PM
variable variable
|
Anonymous
Anonymous
Unregistered
|
I want to create a variable who's name would depend on another variable, but my brain is not working very well today and I can't figure out how to do itAn example: if $extn="PST" create $PST_SIZE=0
|
|
Top
|
|
|
|
#60963 - 2001-12-03 03:56 PM
Re: variable variable
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Hi John,You can use the execute function for that, example:
break on $extn = "PST"
if $extn="PST" $=execute("$PST_SIZE=55") endif
?"pst_size=" $pst_size
exit 1
Hope this helps.
-Shawn [ 03 December 2001: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#60964 - 2001-12-03 04:11 PM
Re: variable variable
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Actually, this is proably more what you had in mind:
break on $EXTN = "PST"
if $EXTN = "PST" $=execute("$$$EXTN"+"_SIZE=55") endif
if vartypename($pst_size) = "long" ?"variable=" $pst_size endif
exit 1
-Shawn ok, you had something else in mind ? This is similar to your orginal post without using execute ... it creates dynamic variables as well ... just not as dynamic as with the execute function ...
break on $EXTN = "PST"
select
case $EXTN = "PST"
$PST_SIZE = 0
case $EXTN = "XXX"
$XXX_SIZE = 0
endselect
exit 1
The variables are created (declared) conditionally. But no matter how you slice it, there'll be a lot of conditional coding to make any strategy like this work ... what you want to do this for exactly ? -Shawn [ 03 December 2001: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#60965 - 2001-12-03 05:05 PM
Re: variable variable
|
Anonymous
Anonymous
Unregistered
|
ok here's the plan,I am trying to search for user files on the C:\drive. So I have declared a variable array $search_key="c:\*.pst;c:\*.doc;c:\*.vsd;c:\*.xls;c:\*.mpp;c:\*.mdb" I then use the DOS dir command to search for these files and return them to a txt file. I then use kix to get file size for each file, work out the extension type and add the size to a variable that would be based on the extension type at the end of the script I would need to echo each of the variables back to say that the script had found PST files totaling XXXX bytes, DOC files totaling XXXX bytes, etc, etc. I created the script using select case endselect, which you also came up with, however I would like to make it easy for noddy admins to add an additional file type to search for by just adding it into the string $search_key (see above) without editing the script further down... does this make sense? I am just thinking that a 2D array maybe more appropriate but that kinda stuff is way over my head 
|
|
Top
|
|
|
|
#60966 - 2001-12-03 06:22 PM
Re: variable variable
|
Anonymous
Anonymous
Unregistered
|
I have given up on this hare-brained scheme, and gone back to the select case end select that shawn mentioned earlier.
|
|
Top
|
|
|
|
#60968 - 2001-12-03 07:08 PM
Re: variable variable
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
John, I,m kinda embarrassed with this one because it's so low-tech and it doesn't use arrays ... it uses the "indexed file" type behaviors of INI files to keep a tally of extention stats ... probably be a real performance pig after a while too ... And your right, the only other way I can think to do it is with arrays (which means array lookups as well) or with dynamic coding with the execute function (like your orginal thought) ... both are totally doable but at what cost ? (performance/maintainability, all that) ? It's written with KiXtart 4.1 (have to have the latest because of the instrrev() function) ...
break on $profile = "@curdir\enumdir.ini" $tempfile = "@curdir\enumdir.tmp"
$search = "c:\*.doc;c:\*.kix"
shell '%comspec% /c dir $search /s/b >"$tempfile"'
$= writeprofilestring($profile,"dirs","","") ; clear list
if open(1,$tempfile) = 0 $filename = readline(1) while @error = 0 if $filename $extention = substr($filename,instrrev($filename,".")+1,3) $total = val(readprofilestring($profile,"dirs",$extention)) $total = $total + getfilesize($filename) $= writeprofilestring($profile,"dirs",$extention,$total) endif $filename = readline(1) loop $=close(1) endif
for each $extention in split(readprofilestring($profile,"dirs",""),chr(10)) if $extention ?"$extention has " readprofilestring($profile,"dirs",$extention) " bytes used" endif next
exit
Anyway, food for thought eh ? -Shawn
|
|
Top
|
|
|
|
#60973 - 2001-12-03 09:29 PM
Re: variable variable
|
Anonymous
Anonymous
Unregistered
|
Shawn, this is an admin script (sort of) We are swallowing up a sister company at the moment. They have little in the way of policies so we have no idea how much data will need to be moved off there PC's and onto network drives, also we are not sure exactly what apps they have (builds are not tied down ) I was writing a script to excecute on each PC, to gather information about each one. But as I will be in New york when the engineers will be running the script, I was trying to make it easy for them to modify variables etc (none of them are into Kix)
|
|
Top
|
|
|
|
#60974 - 2001-12-03 10:10 PM
Re: variable variable
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
John,based off of the conversation here. here is a modified version of my above script. it gives a report of spaced used on all file types. $files = dirplus("c:\bryce\mp3","*.*",1,1)for each $file in $files if instr($types,$file.type) = 0 $types = $types + $file.type + "," endif next $types = split($types,",") redim preserve $types[ubound($types)-1] for each $type in $types $typesize = 0 $buffer = " " for each $file in $files if $file.type = $type $typesize = $typesize + $file.size endif next ? "$typesize" + substr($buffer,len($typesize),len($Buffer)) + $type next
here is the output 719 BAS File 4868 Microsoft Excel Comma Separated Values File 226600 Microsoft HTML Document 5.0 351519680 File Folder 2421248 Application Extension 4457 CNT File 28392 GID File 203962 Help File 4182 Configuration Settings 1745342 WinZip File 214381 Text Document 1409 DIZ File 10053 EL! File 546 MS-DOS Application 82 OLD File 227948 LIB File 114598 GIF Image 11639 JPEG Image 48883458 PRJ File 801 DAT File 2998 Icon 2874 IDX File -530113234 Winamp media file 15130 ISU File 4433 MS-DOS Batch File 708 Cascading Style Sheet Document 114967 PS File 3689 Winamp playlist file 1049 KixTart 6201348 Movie File (MPEG) 4335 PRE File 1659 CDB File 1575216 Bitmap Image 3957 LKS File 195 Paint Shop Pro 5 Image 299 Q2 File
i do not know why Winamp media file is -530113234. But i do have a lot of them in this folder.
|
|
Top
|
|
|
|
#60975 - 2001-12-04 03:02 PM
Re: variable variable
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Bryce, I bet you have more than 2,147,483,647 bytes in your Winamp directory  It's only the max limit of an integer in Kixtart. Seems that Kix continue from -2,147.... when the max is reached.[ 04 December 2001: Message edited by: Popovk ]
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
#60976 - 2001-12-04 04:41 PM
Re: variable variable
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
hmmm yep... 3 gigs in that folder
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|