Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can you show a directory of a computer?
#1
Hey there peoples, I was just wondering (I am going to keep this short because everyone gets mad at me for sounding newbie-ish) if there was a way to display all the files in a certain folder thru QBASIC... for example

C:\windows
file
file
file
file


and so on
I want something like what was done in AWDRAW or whatever it was called. So I want it to, essentially, go thru the entire listing of all the files and folders of C:\windows. Is it possible? Thanks for any help you can give.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#2
You have to call dir, redirect its output to a file, and then read that file.

Code:
whatdir$ = "C:\WINDOWS" ' for example
PRINT whatdir$
SHELL "dir " + whatdir$ + " /b >list.txt"
OPEN "list.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
   LINE INPUT #1, FileName$
   PRINT FileName$
WEND
CLOSE #1
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
Hey! That's gonna come in handy! I'm surprised I didn't ask this myself!
Reply
#4
Hey guys thanks for the help I appreciate it, since I am such a newbie programmer, eh? I might have been able to figure it out myself, but hey, I figured I'd save myself the time and ask someone online line Na_th_an or something, cause he prob'ly knows and stuff.....

Megaman glad yous got interested. I wanted to know this so I can create a fake virus program that 'simulates' deleting the hard drive and all that nonsense (but it really DOESN'T delete...) So thanks for all your help.

-Nova
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#5
Quote:You have to call dir, redirect its output to a file, and then read that file.

Code:
whatdir$ = "C:\WINDOWS" ' for example
PRINT whatdir$
SHELL "dir " + whatdir$ + " /b >list.txt"
OPEN "list.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
   LINE INPUT #1, FileName$
   PRINT FileName$
WEND
CLOSE #1

It's retarded that there isn't a better way to do it, but that's it right there. Some libs have commands for this. (DQB, I believe)
Reply
#6
I use the shell "dir *.fil /b >file.lst" method too. Dave Cleary wrote a qb4.5 version of PDS' DIR$ function. You can download the file at http://qbasicnews.com/files/dir.bas[best to download]

You can use it in qbasic 1.1 if you download the interrupt routine from the ABC archives.

Code:
'DIR.BAS by Dave Cleary
DEFINT A-Z
DECLARE FUNCTION DIR$ (FileSpec$)

'$INCLUDE: 'QB.BI'
'-----  Some constants that DIR$ uses
CONST DOS = &H21
CONST SetDTA = &H1A00, FindFirst = &H4E00, FindNext = &H4F00
'--------------------------------------------------------------------

FUNCTION DIR$ (FileSpec$) STATIC

   DIM DTA AS STRING * 44, Regs AS RegTypeX
   Null$ = CHR$(0)

'-----  Set up our own DTA so we don't destroy COMMAND$
   Regs.AX = SetDTA                    'Set DTA function
   Regs.DX = VARPTR(DTA)               'DS:DX points to our DTA
   Regs.DS = -1                        'Use current value for DS
   InterruptX DOS, Regs, Regs          'Do the interrupt

'-----  Check to see if this is First or Next
   IF LEN(FileSpec$) THEN              'FileSpec$ isn't null, so
                                'FindFirst
     FileSpecZ$ = FileSpec$ + Null$   'Make FileSpec$ into an ASCIIZ
                                'string
     Regs.AX = FindFirst              'Perform a FindFirst
     Regs.CX = 0                      'Only look for normal files
     Regs.DX = SADD(FileSpecZ$)       'DS:DX points to ASCIIZ file
     Regs.DS = -1                     'Use current DS
   ELSE                                'We have a null FileSpec$,
     Regs.AX = FindNext               'so FindNext
   END IF

   InterruptX DOS, Regs, Regs          'Do the interrupt

'-----  Return file name or null
   IF Regs.Flags AND 1 THEN            'No files found
     DIR$ = ""                        'Return null string
   ELSE
     Null = INSTR(31, DTA, Null$)     'Get the filename found
     DIR$ = MID$(DTA, 31, Null - 30)  'It's an ASCIIZ string starting
   END IF                              'at offset 30 of the DTA

END FUNCTION
Reply
#7
To display the files of the current dir, just check the FILES command.

If you want to build a directory browser, you can find 3 of them at my page, they may help you (feel free to use them as they are, if you don't find them too ugly)
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)