Page 1 of 2 12>
Topic Options
#32001 - 2002-11-07 07:20 PM Variable on the fly
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
I hope someone can help me. I have looked all over the BB but could not find what I am looking for. What I am trying to do is get a group of files in a directory and put the file name in a variable and then choose the variable to restore the file. I can get the list of files just fine, my problem is that some of the files are long and time is important. So what I wanted to do was as I was reading the lines out of the text file to create a variable on the fly to put the name of the file into. This way I can use a 1, 2, 3, etc as the names of the variable and that would be all the user would have to type.

code
****************************************
cls
?
?
?
?
?
"Enter The Hour You Want To Restore (ie. 1000, 1100, 1200, 1300, 1400, etc): "
gets $selecthour
$trimhour = left("$selecthour", 2)

$datalocation = "s:\vcare4x2"
$filelocation = "\backup\database\hour\"
$searchlocation = "$datalocation" + "$filelocation"
$Filenum = 1
$filename = "*." + "$trimhour"

; temp file
$tmpfile = "c:\results.txt"

; write to file.
CD "$searchlocation"
SHELL "%comspec% /c dir /b $filename > $tmpfile"

; read results.
OPEN(1,$tmpfile,2)
$string = READLINE(1)
WHILE @ERROR = 0

; split the result in path and filename.
$path = ""
$file = $string
;? $file
If $string = ""
goto finish
Else
?"$filenum" + ") " + "$string"
Endif

WHILE INSTR($file,"\")
$path = $path + SUBSTR($file,1,INSTR($file,"\"))
$file = SUBSTR($file,INSTR($file,"\")+1,LEN($file))
LOOP
$string = READLINE(1)
$filenum = $filenum + 1
$filemessage = $filemessage + $filenum

LOOP
CLOSE(1)
goto getdata

:getdata
$select = messagebox("Please Choose A Number of The Data File You Want To Restore", "Data File To Restore", 65569)
?"Enter Number: "
gets $number

:finish

DEL $tmpfile
***************************************

Thanks for the help

Top
#32002 - 2002-11-07 07:24 PM Re: Variable on the fly
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
you can use an array...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#32003 - 2002-11-07 07:25 PM Re: Variable on the fly
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Use WSHPIPE() to get the array of filenames. I have code posted that does just that.

[ 07. November 2002, 19:25: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#32004 - 2002-11-07 07:27 PM Re: Variable on the fly
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
agreed, i would strongly discourage you from doing what your proposing ... better approach is to simply count the number of files you have into $count, dynamically dimemsion an array[$count], then take the index number the user provides and index into the array and off you go. can do much better bounds checking this way ... plus, your script will never be sensitive to the number of files in the folder.

[ 07. November 2002, 19:28: Message edited by: Shawn ]

Top
#32005 - 2002-11-07 07:29 PM Re: Variable on the fly
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Hmm, perhaps that what you get when you say "looked all over the BB".

One small hint to use an array, a second that elaborates a bit suggesting a UDF to use an array, and a third with a tad more detail.

The UDF you can find well... in our UDF Library.

[ 07. November 2002, 19:44: Message edited by: LLigetfa ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32006 - 2002-11-07 07:29 PM Re: Variable on the fly
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
this is the code I use for random wallpapers...

code:
$button1=messagebox("Do you want a random wallpaper?","Random Wallpaper",36,9)
if $button1=6
dim $paper[1]
$rc=SRND(@MSECS)
$count=0
$paperdir=dir("$logon\wallpaper\*.bmp")
while @error=0
REDIM PRESERVE $paper[$count+1]
$paper[$count]=$paperdir
$count=$count+1
$paperdir=dir()
loop
:randpaper
$rnum=rnd($count)
$wallpaper=$paper[$rnum]
$=writevalue("$HKCPCPD","WallpaperStyle","2",REG_SZ)
$=setwallpaper("$logon\wallpaper\$wallpaper")
$button2=messagebox("Do you want to set this as your default wallpaper?","Random Wallpaper",36)
if $button2=6 ;yes
$MyPictures=readvalue("$HKCUSMWCV\Explorer\Shell Folders","My Pictures")
copy "$logon\wallpaper\$wallpaper" "$MyPictures\kixtart.bmp"
$=writevalue("$HKCPCPD","Wallpaper","$MyPictures\kixtart.bmp",REG_SZ)
endif
if $button2=7 ;no
goto randpaper
endif

Adjusted by the long-line police [Big Grin]

[ 07. November 2002, 19:36: Message edited by: Howard Bullock ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#32007 - 2002-11-07 07:30 PM Re: Variable on the fly
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Here's the code:
code:
$Files=WshPipe("%comspec% /c dir /s /b c:\data\scripts\fasttrack",1)
? "There are " + (ubound($Files)+1) + "files."
for each $file in $Files
$file = substr($file,instrrev($file,"\")+1)
? $file
next

You will have to WSHPIPE() from the UDF Library.

[ 07. November 2002, 19:34: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#32008 - 2002-11-07 07:30 PM Re: Variable on the fly
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why not use the DirPlus() UDF to generate an array of filenames?
_________________________
There are two types of vessels, submarines and targets.

Top
#32009 - 2002-11-07 07:31 PM Re: Variable on the fly
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
wheres the long-line police when you need 'em ? [Wink]

We're here [Big Grin] Is it short enough?

[ 07. November 2002, 19:39: Message edited by: Howard Bullock ]

Top
#32010 - 2002-11-07 07:36 PM Re: Variable on the fly
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
This BBChecker unleashed a monster. [Eek!]
Before I could get a decent reply off, everyone, in a race for 'first-itis', already had tidbits posted.

As for long lines... I've seen a lot worse. I run a 24" monitor at 1280x1024 so the line's gotta be pretty long before I start flaming.

[ 07. November 2002, 19:45: Message edited by: LLigetfa ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32011 - 2002-11-07 07:39 PM Re: Variable on the fly
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I was first. [Big Grin]

Do you all have nothing better to do than sit around waiting for the world to ask a Kix problem...

Is someone paying you for this??? It can't be on your job descriptions [Big Grin] [Big Grin]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#32012 - 2002-11-07 07:43 PM Re: Variable on the fly
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Rad,
Care to post YOUR job description? [Razz]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32013 - 2002-11-07 07:44 PM Re: Variable on the fly
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
State government employee [Big Grin] [Big Grin]

your tax dollars at work...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#32014 - 2002-11-07 07:46 PM Re: Variable on the fly
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well, not MY CDN tax dollars anyway.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32015 - 2002-11-07 07:49 PM Re: Variable on the fly
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I dunno... lots of Canadians in Florida [Smile]

Florida doesn't have State tax (just sales tax) That is why I said "your tax dollars" [Big Grin]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#32016 - 2002-11-07 07:51 PM Re: Variable on the fly
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
Thanks for all your suggestions!!!!

Les.... I am the LAN Manager at a state hospital

Top
#32017 - 2002-11-07 07:56 PM Re: Variable on the fly
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I try not to stray too far from home. I also avoid state taxes by exporting and try not to get sick whilst stateside.

Now I understand why your health care cost are so high. [Wink]

BTW, you don't say what state.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32018 - 2002-11-07 07:57 PM Re: Variable on the fly
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
"Use the Force, Luke"
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#32019 - 2002-11-07 08:04 PM Re: Variable on the fly
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
I'm in Virginia.....

Word of WARNING do not work for the state. I have only been with the state for about 5 years and for the past 3, I have one tech for every 300 computers.

Top
#32020 - 2002-11-07 08:15 PM Re: Variable on the fly
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
btw..

I just threw this together, I may post this to UDF, but I don't know how many DIR UDFs we need.

code:
break on
call \\a06\logon\udf.kix

$dir=Enumdir("\\a06\logon\wallpaper","*.bmp")

for each $file in $dir
? $file
next

exit

Function Enumdir($directory, optional $mask, Optional $Subdir)
dim $dircmd

if $subdir $subdir='/s' endif
$dircmd='%comspec% /c dir "$directory\$mask" /b $subdir'

if exist("$directory")
$Enumdir=WshPipe($dircmd,1)
else
exit 1
endif
endfunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 595 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.11 seconds in which 0.061 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org