Qbasicnews.com

Full Version: List of files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
How do you get a list of files in qb for a load menu? I know you could use Shell "dir /b *.*" but it exits to the command prompt when it does that, so I can't use a VESA mode. Any help?
Searchfile routine neolib uses:

[syntax="Qbasic"]FUNCTION neoDOSsearchFile$ (FileMask AS STRING) STATIC
'searches for a file
'- FileMask: specifies the mask of the file to search for
' => String: search for that file (e.g. "*.BMP")
' => Null String: search for the next file with previous attributes

DIM DTA AS STRING * 44

RegsX.ax = &H1A00
RegsX.dx = VARPTR(DTA)
RegsX.ds = -1
INTERRUPTX &H21, RegsX, RegsX 'set disk transfer address

IF FileMask <> "" THEN
RegsX.ax = &H4E00
RegsX.cx = 0
RegsX.ds = -1
FileMaskZ$ = FileMask$ + CHR$(0)
RegsX.dx = SADD(FileMaskZ$)
ELSE
RegsX.ax = &H4F00
END IF
INTERRUPTX &H21, RegsX, RegsX
IF RegsX.flags AND 1 THEN
neoDOSsearchFile$ = ""
ELSE
WhereIsEnd = INSTR(31, DTA, CHR$(0))
ans$ = MID$(DTA, 31, WhereIsEnd - 30)
IF ans$ <> "" THEN ans$ = LEFT$(ans$, LEN(ans$) - 1)
neoDOSsearchFile$ = ans$
END IF
END FUNCTION[/syntax]
(Cred to the original author of DIR$... can't remember who it is :-?)

Be sure to declare RegsX as RegTypeX (in QB.BI), and to enable QB.LIB using the /L option on QB.

It works like:
Code:
FileFound$ = neoDOSsearchFile$("*.bmp")
'^^ returns the FIRST file found that matches *.bmp
FileFound$ = neoDOSsearchFile$("")
'^^ returns the NEXT file found that matches *.bmp

' You can continue printing files until neoDOSsearchFile$ return "" (null string), which indicates no more files are found.

So to get a list of all files in current dir:
Code:
a$ = neoDOSsearchFile$("*.*")
DO UNTIL a$ = ""
   PRINT a$
   a$ = neoDOSsearchFile$("")
LOOP

Unlike many of these static functions, they're not threadproof (if used in fb).

Hope it helped a bit =)
if you could use QBX (qb71) just would need to use the command DIR$, but if you wnat to use interrupts, try seeing the microsoft's article number 41,447 at
http://support.microsoft.com/default.asp...EN-US&FR=0
I've never heard of the DIR$ command before. Probably because before this I always used qb45 and now I only ever go through the PDS compiler....That's cool! Also Neo, would you mind explaining how exactly your code works? Because I'm not too familiar with BIOS calls, except to start the mouse. Another thing I forgot to ask: How do you check for directories?
this is a program that i made for my qb messenger, it will run in a window under windows 95/98/me/2000/xp the same as my messenger program. Allowing user to still interface with windows.
the only limitation is 1000 files per 1000 folders.
although this is a big program, the part that builds the file lists is quite simple.
I cant remember where i got the build mouse function. Thank you to whoever you are.

Cls
On Error GoTo errorhandle
Dim filename(1000) As String * 12
Dim dirname(1000) As String * 12
Dim mouse$
GoSub makedummydir
'Screen 9 '***** keep it rem'd to run in window.
GoSub buildmouse
GoSub INIT
resett:


GoSub makefiledata
GoSub makedirdata
GoSub GRAPHICS
fls = 1: dls = 1
fl = 1: GoSub DRWFILE:
fl = 1: GoSub DRWDIR

GoSub show

start:
k$ = INKEY$

GoSub status
LOCATE 20, 1: Print "x-"; xmouse%
LOCATE 21, 1: Print "y-"; ymouse%
If lb% = -1 Then GoSub hide: GoSub checkfilename: GoSub checkdir: GoSub show
If k$ = "" Then GoTo start
If k$ = Chr$(27) Then End
'LOCATE 2, 1: PRINT "*"; k$; "*"
flss = fls
dlss = dls
If k$ = Chr$(0) + "P" Then fls = fls + 10
If k$ = Chr$(0) + "H" Then fls = fls - 10
If k$ = Chr$(0) + "M" Then dls = dls + 1
If k$ = Chr$(0) + "K" Then dls = dls - 1
If dls + 8 > dln Then dls = dlss
If dls < 1 Then dls = 1
If fls + 20 > fln Then fls = flss: GoTo start
If fls < 1 Then fls = 1: GoTo start
fl = fls
GoSub hide
GoSub DRWFILE
fl = dls
GoSub DRWDIR
GoSub show
GoTo start

checkfilename:
nx = Int(xmouse% / 8) + 1: ny = Int(ymouse% / 14) '14'8 with no screen
nx = Int(1 + Int(nx / 16)) + Int(fls / 10)
If ny < 1 Or ny > 10 Or xmouse% < 4 Or xmouse% > 504 Then Return
LOCATE 13, 3: Print "Filename: "; filename((nx * 10) - 10 + ny)
Return

DRWFILE:
y = 2: x = 5
For v = fl To fl + 39
LOCATE y, x: Print " "
If v <= fln Then LOCATE y, x: Print filename(v)
y = y + 1: If y > 11 Then y = 2: x = x + 15
Next
Return

DRWDIR:
For v = 2 To 11: LOCATE v, 66: Print " ": Next
For v = 2 To 11
If fl <= dln Then LOCATE v, 66: Print dirname(fl)
fl = fl + 1
Next
Return

makefiledata:
fln = 0
Shell "dir /ogn/b/-p/-s/a:-d *.* >FILList.dat"
Open "FILlist.dat" For Input As #1
Do Until EOF(1)
fln = fln + 1
Input #1, filename(fln)
If filename(fln) = "FILLIST.DAT " Or filename(fln) = "DIRLIST.DAT " Then fln = fln - 1
Loop: Close
Return

makedirdata:
dirname(1) = ".."
dln = 1
Shell "dir /ogn/b/-p/-s/a:d >DIRList.dat"
Open "DIRlist.dat" For Input As #1
Do Until EOF(1)
dln = dln + 1
Input #1, dirname(dln)
Loop: Close
Kill "FILLIST.DAT": Kill "DIRLIST.DAT"
Return

checkdir:
If xmouse% < 508 Or xmouse% > 632 Then Return
If ny > 10 Or ny < 1 Then Return
v$ = RTrim$(dirname(ny + dls - 1))
ChDir v$
GoSub status
RETURN resett


makedummydir:
'FOR v = 14 TO 20
'x$ = STR$(v)
'v$ = MID$(x$, 2, 2)
'RMDIR v$
'NEXT
Return




GRAPHICS:
Color 4, 0
LOCATE 1, 1: Print Chr$(218)
LOCATE 1, 80: Print Chr$(191)
LOCATE 14, 1: Print Chr$(192)
LOCATE 14, 80: Print Chr$(217)
LOCATE 1, 2: Print String$(78, 196)
LOCATE 12, 2: Print String$(78, 196)
LOCATE 14, 2: Print String$(78, 196)
For v = 2 To 11
LOCATE v, 1: Print Chr$(179)
LOCATE v, 80: Print Chr$(179)
LOCATE v, 64: Print Chr$(179)
Next
LOCATE 13, 1: Print Chr$(179); Space$(78); Chr$(179)
LOCATE 12, 1: Print Chr$(195)
LOCATE 12, 80: Print Chr$(180)
LOCATE 12, 64: Print Chr$(193)
LOCATE 1, 64: Print Chr$(194)
Color 15
Return

buildmouse:
mouse$ = Space$(57)
For I% = 1 To 57
READ A$
H$ = Chr$(Val("&H" + A$))
Mid$(mouse$, I%, 1) = H$
Next I%
DATA 55,89,E5,8B,5E,0C,8B,07,50,8B,5E,0A,8B,07,50,8B
DATA 5E,08,8B,0F,8B,5E,06,8B,17,5B,58,1E,07,CD,33,53
DATA 8B,5E,0C,89,07,58,8B,5E,0A,89,07,8B,5E,08,89,0F
DATA 8B,5E,06,89,17,5D,CA,08,00
Return

DRIVER:
DEF SEG = VARSEG(mouse$)
mouse% = SADD(mouse$)
Call Absolute(AX%, BX%, CX%, DX%, mouse%)
Return

INIT:
AX% = 0
BX% = 0
CX% = 0
DX% = 0
GoSub DRIVER
MIT% = AX%
Return

hide:
AX% = 2
BX% = 0
CX% = 0
DX% = 0
GoSub DRIVER
Return

'MPUT:
' AX% = 4
' CX% = X%
' DX% = Y%
' GOSUB DRIVER
'RETURN

show:
AX% = 1
BX% = 0
CX% = 0
DX% = 0
GoSub DRIVER
Return

status:
AX% = 3
GoSub DRIVER
lb% = ((BX% And 1) <> 0)
RB% = ((BX% And 2) <> 0)
xmouse% = CX%
ymouse% = DX%
Return

errorhandle:
If Err = 76 Then Resume Next: 'path not found '
LOCATE 1, 1: Cls: Print Err
End
'ERROR ERR
well, everyone is using some means of a complex routine that doesn't have to be so hard

[syntax="qbasic"]DECLARE SUB GetFiles(path AS STRING, list() AS STRING)
'(..)

REDIM Files(0) AS STRING
GetFiles("./", Files())
FOR i% = LBOUND(Files) TO UBOUND(Files)
PRINT Files(i%)
NEXT i%

END

SUB GetFiles(path AS STRING, list() AS STRING)
shell$ = "DIR " + path + " /On /B > temp.tmp"
SHELL(shell$)

DIM tmp AS INTEGER
tmp = FREEFILE
OPEN "temp.tmp" FOR INPUT AS #tmp
DO UNTIL EOF(tmp)
REDIM list(UBOUND(list)+1) '' Should increment by one
INPUT #tmp, list(UBOUND(list))
LOOP
CLOSE #tmp
KILL "temp.tmp"
END SUB[/syntax]

THat should do the trick nicely

Oz~
Maybe start reading before posting:
Quote: I know you could use Shell "dir /b *.*" but it exits to the command prompt when it does that, so I can't use a VESA mode. Any help?
In other words, he doesn't want to use dir.
Neo, you'll have to explain this fancy "read" thing...fascinating! Big Grin
I have a program that use's interupt to get file names of diretory's and also keeps track of directories, sorry i didnt read the post fully,if you need the program to do this,drop a line saying so,i will post it.
Quote:How do you get a list of files in qb for a load menu? I know you could use Shell "dir /b *.*" but it exits to the command prompt when it does that, so I can't use a VESA mode. Any help?
How about using a batch file for support.
1) Compile your program to a .exe
2) Write a batch file like this:
Code:
@ECHO OFF
DIR *.* /B > TEMPDIR
YOURPROG.EXE
Your program then reads the list from the TEMPDIR file.
If you want the list sorted, add this parameter to the DIR: /ON

Then, instead of running your program directly, you run the batch file. It ain't sexy, but it's simple.
*****
Pages: 1 2 3