Page 1 of 1 1
Topic Options
#49993 - 2000-05-23 02:07 PM Select file script.
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Ok, so i had nothing better to do today

I wrote this script for a project that i am working on that requires a user to select a file.

you can dl it here http://www.neosoft.com/~brycel/kix/other_scripts/Select_File/Select_File.kix


code:

;==================================================================================
; this script will display a list of files in a directory, and ask you what file
; you want to pick.
;
; You can edit the following variables, to change how you want the display to look.
;
; $colstart...the stating position of the columes
; $RowStart...the starting position of the rows
; $lastrow....This is the bottom row that you want the display on
; $nextcol....how far apart you want the collums
; $maxcol.....total number of Columes
;
; Standard Dos window
; $colstart = 0
; $RowStart = 0
; $lastrow = 23
; $nextcol = 25
; $maxcol = 3
;
; The best way to run this script is to call it from another script
; (call "file.kix")
;
; You can set a global var in the main script,
; $directory = the directory that you want to list
; $directory = "c:\temp"
; setting this var will show you a display of that directory, and ask
; you to pick a file from that dir, otherwise it will use the current
; directory.
;
; This program returns with the var $Selected_File, that you can then use as you
; wish. $Selected_file = 0 of nothing was selected.
;==================================================================================
break on cls
DIM $temp[9999] DIM $dn
DIM $Arraystart DIM $row
DIM $colstart DIM $col
DIM $RowStart DIM $Arraycount
DIM $lastrow DIM $number
DIM $nextcol DIM $tempfile
DIM $maxcol DIM $q
DIM $CurrentDrive DIM $CurrentDir
DIM $Drive DIM $dir

$colstart = 1
$RowStart = 1
$lastrow = 23
$nextcol = 25
$maxcol = 3

$Arraystart = 1
$arraycount = $arraystart
$tempfile = "tempfile.dat"
$CurrentDrive = substr("@curdir",1,2)
$Currentdir = substr("@curdir",3,len("@curdir")-2)

;$directory = "%systemroot%" ;uncomment for testing only

gosub Build_Array
gosub File_Display

;? $Selected_file ; uncomment for testing only


quit

;==================================================================================
;==================================================================================

:File_Display
cls
$DN = $arraystart
$row = $rowstart
$col = $ColStart

while $dn <= $arraycount
at($row,$col) "[$DN]..." + $temp[$dn]
$dn = $dn + 1
$row = $row + 1

if $row >= $lastrow
$col = $col + $nextcol
$row = $rowstart
endif

if $col >= $nextcol * $maxcol
at($lastrow + 1,$col-$nextcol-5) "press ENTER for next screen"
gosub question
if $Selected_File <>""
return
endif
cls
$col=$Colstart
endif
loop

:question
at($lastrow+1,0)" "
at($lastrow+1,0)"Please Pick a Number: "
gets $number
$number = val("$number")
select
case $number > $arraycount or $number < 0
beep goto question
case $number = ""
;end, do nothing
case 1
$Selected_File = $drive + $dir + $temp[$number]
endselect
return

;==================================================================================
:Build_Array
if $directory <> 0
select
case instr("$directory", ":") = 2
$Drive = substr("$directory",1,2)
if substr("$directory",len("$directory"),1) = "\"
$dir = substr("$directory",3,len("$directory")-2)
else
$dir = substr("$directory",3,len("$directory")-2) + "\"
endif
case 1
$Drive = substr("@curdir",1,2)
if substr("$directory",len("$directory"),1) = "\"
$dir = $directory
else
$dir = $directory + "\"
endif
endselect
else
$drive = $CurrentDrive
$dir = $CurrentDir
endif
go "$drive"
cd "$dir"
?"Building Array....."

shell "%comspec% /c dir /a-d /b > $tempfile"
$q = open(1,"$tempfile",2)
$temp[$arraycount] = readline(1)
while $temp[$arraycount] <> ""
$arraycount = $arraycount + 1
$temp[$arraycount] = readline(1)
loop
$arraycount = $arraycount - 1
$q = close(1)
del $tempfile
return


Bryce

[This message has been edited by Bryce (edited 23 May 2000).]

Top
#49994 - 2000-05-24 05:45 AM Re: Select file script.
Happy Birthday cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Cool menu, found a bug

Line 96: was $Selected_File = $drive + $dir + $temp[$number]

should be: $Selected_File = $drive + $dir + "\" + $temp[$number]

Without the \ I got h:\directoryfilename instead of h:\directory\filename.

cj

Top
#49995 - 2000-05-24 07:24 AM Re: Select file script.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Bryce:

Boy - you Texans' really do - do things bigger down there !

Well done ! I like how you write generic and re-usable code.

This would make a nice addition to a well rounded KiX library.

Let's see - what else would one need ? Hmmm...

How about a generic "message" box and a generic "common" dialogue box and a generic "list" box ( which could be turned into a generic menu box ).

Word o' the day : Generic

Or - how about a KiX wrapper script that displays a menu bar across the top of the dos window ( you know - with "File" "Edit" "Search" "Help" ).

One can pull down menus, select menu items, and this wrapper will call custom functions in the "wrapped" script ?

Shawn.

Top
#49996 - 2000-05-24 10:13 AM Re: Select file script.
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
CJ, you are right! didn't catch that one.

also fixed, a bug that was there if no $directory var was set from the calling script. (the bug that cj might have been talking about) and a weird problem that was happening if you had spaces in your directory path. i also rewrote the way that the script collected the information in the target $directory.
http://www.neosoft.com/~brycel/kix/other_scripts/Select_File/Select_File.kix

Bryce


Bryce

Top
#49997 - 2000-05-25 02:05 PM Re: Select file script.
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I have updated this script, you can dl it here.
http://www.neosoft.com/~brycel/kix/other_scripts/Select_File/Select_File.kix

also i have created a select Directory script that works like the select file script.
http://www.neosoft.com/~brycel/kix/other_scripts/Select_File/Select_Dir.kix

Bryce


Top
Page 1 of 1 1


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

Who's Online
0 registered and 4873 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.063 seconds in which 0.033 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