TGC Codebase Backup



Easy file / drive browser by NE0

10th Nov 2003 12:03
Summary

An example source code on how to make a drive browser... easy as <sencored> :)



Description

This will learn you how to make a drive browser using only text and colors...

use the mouse to select a folder and the up/down keys to scroll the list



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem -----------------------------------------------
Rem -- Author : Vincent Hoogendam                --
Rem -- Demo   : How to make a file listbox       --
Rem -- E-mail : vincent.hoogendam@lycos.nl       --
Rem -----------------------------------------------
Rem -- version [1.0 - Simple text only]          --
Rem -----------------------------------------------

Rem first we define a starting directorie and perform search for files in that directorie
rem -------------------------------------------------------------------------------------
Set dir "c:"
Perform checklist for files                                 :

Rem now lets make some storage room to store filenames in that were found
Rem ---------------------------------------------------------------------
f_name$ as string
f_type# as integer
first# as integer
last# as integer
option# as integer

Dim f_name$(5000)
Dim f_type#(5000)


Rem set the backdrop on and scramble stars position
Rem -------------------------------------------------------
backdrop on
color backdrop 0


Rem now store file types and names into memory
Rem ------------------------------------------
printout:
Perform checklist for files
first#=0
Find first
f_name$(0) = get file name$()
f_type#(0) = get file type()

For a=1 to checklist quantity()-1
   find next
   f_name$(a) = get file name$()
   f_type#(a) = get file type()
Next a

Rem all files / folders in the current directory are now stored in memory
Rem let`s print them out on the screen
Rem ---------------------------------------------------------------------
if checklist quantity()>28
   last# = 28
else
   last# = checklist quantity()
endif


do
rem Check if the mouse is over a file
Rem ---------------------------------
for a=1 to 29
   if mousey() > a * 15 and mousey() < (a * 15) + 15 then box 0,a*15,640,(a * 15)+ 15 : option# = a
next a

set cursor 0,0
ink rgb(0,0,255),1
print get dir$()
line 0,13,640,13
y# = 0

for a = first# to last#
set cursor 0,(y# * 15) + 14
   if f_type#(a)=1
      ink rgb(255,0,0),1
   else
      ink rgb(255,255,255),1
   endif
   print f_name$(a)
   y# = y# + 1
next a
ink rgb(55,55,55),0


Rem scroll the list with your keyboard
Rem ----------------------------------
if upkey() = 1 and first# > 0
   first# = first# - 1
   last# = last# - 1
endif

if downkey() = 1 and last# < checklist quantity() - 1
   last# = last# + 1
   first# = first# + 1
endif

Rem if the mouse is clicked and you have clicked on a directory then change to that directory
Rem -----------------------------------------------------------------------------------------
if wait#=0

if mouseclick()=1 and f_type#(((option# - 1) + first#)) = 1
   gosub change_dir
endif

else
   time#=time#+1
   if time#=100 then time#=0 : wait#=0
endif

Rem Show which file you have selected at the bottem
Rem -----------------------------------------------
line 0,(29*15)+17,640,(29*15)+17
set cursor 0,(29*15)+18

if f_name$(((option# - 1) + first#)) = ".."
   Print "[Click to go up one folder]"
   gosub skip
endif

if f_name$(((option# - 1) + first#)) = "."
   Print "[Email:Vincent.hoogendam@lycos.nl]"
   gosub skip
endif

if f_type#(((option# - 1) + first#)) = 1
   Print "[Directory:" + f_name$(((option# - 1) + first#)) + "]"
else
   print "[File:" + f_name$(((option# - 1) + first#)) + "]"
endif


skip:
loop

change_dir:
for a = 0 to checklist quantity()
   f_name$(a) = ""
   f_type#(a) = 0
   cd f_name$(((option# - 1) + first#))
   wait#=1
   gosub printout
next a