I wrote this script for a project that i am working on that requires a user to select a file.
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