Directory of CD possible?

General FreeBASIC programming questions.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Directory of CD possible?

Postby bcohio2001 » Mar 10, 2007 15:54

I am trying to read filenames off of a "burned" CDROM. The program works fine for hard drive, but will not work for CD. [also used commercial "game" CD for test]

Code: Select all

#include "vbcompat.bi"
#include "windows.bi"
#include "MyFunc.bi"

OPTION EXPLICIT
'Const FILE_ATTRIBUTE_READONLY = 1 '&H1
'Const FILE_ATTRIBUTE_HIDDEN = 2 '&H2
'Const FILE_ATTRIBUTE_SYSTEM = 4 '&H4
'Const FILE_ATTRIBUTE_DIRECTORY = 16 '&H10
'Const FILE_ATTRIBUTE_ARCHIVE = 32 '&H20
'Const FILE_ATTRIBUTE_NORMAL = 128 '&H80
'Const FILE_ATTRIBUTE_TEMPORARY = 256 '&H100
'Const FILE_ATTRIBUTE_COMPRESSED = 2048 '&H800

DIM AS STRING DriveLetter
REDIM SHARED AS STRING FoldList(100)
DECLARE SUB GetDriveInfo(AS STRING) ' loads file data from disk

DriveLetter = "D"
GetDriveInfo DriveLetter
PRINT "Done."
SLEEP

SUB GetDriveInfo(Drive AS STRING)
    DIM AS STRING FName
    DIM AS INTEGER attribP, FPoint = 0,NFreePoint = 1,f
   
    FoldList(0) = Drive + ":\"
    WHILE FPoint < NFreePoint
        FName = DIR(FoldList(FPoint)+"*",16, @attribP)
        WHILE FName <> ""
            IF LEFT(FName,1) <> "." AND attribP = 16 THEN
                FoldList(NFreePoint) = FoldList(FPoint) + FName + "\"
                NFreePoint += 1
                IF NFreePoint > UBOUND(FoldList) THEN REDIM PRESERVE FoldList(NFreePoint+10)
            END IF
            FName = DIR(@attribP)
        WEND
        FPoint += 1
    WEND
    NFreePoint = FREEFILE
    OPEN "CDTrack.txt" FOR OUTPUT AS #NFreePoint
    PRINT #NFreePoint, STR(UBOUND(FoldList))
    FOR f=0 TO FPoint 'find all files
        PRINT #NFreePoint, FoldList(f)
        'display folder to screen
        print FoldList(f)
        FName = DIR(FoldList(f)+"*",32, @attribP)
        WHILE FName <> ""
            IF (attribP AND 32) THEN
                'display filename to screen?
                print FName
                PRINT #NFreePoint, FName
                PRINT #NFreePoint, Get_File_Stats(FoldList(f),FName)
            END IF
            FName = DIR(@attribP)
        WEND
    NEXT f
    CLOSE #NFreePoint
END SUB
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Postby 1000101 » Mar 10, 2007 16:05

Consider that it might be trying to create "CDTrack.txt" *on* the CD itself and that is why it's failing?
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Postby bcohio2001 » Mar 10, 2007 22:52

1000101 wrote:Consider that it might be trying to create "CDTrack.txt" *on* the CD itself and that is why it's failing?


Commented out all lines with writing to file. No change.

It does not even access the CD at all. Inserted a print FName after the first dir( command in the first while statement. It printed nothing, and I know that there are folders on the CD.

Any other ideas?

THX
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Postby 1000101 » Mar 10, 2007 23:11

hrm, well, I tried to run it to see what results are happening but I lack the functions required (presumible in "MyFunc.bi").

Build it with the debug switches and run it in gdb.
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Postby Zippy » Mar 10, 2007 23:39

@bcohio2001

Please, bear with, we aren't trying to patronize. You need to do 2 things to test.

1. Confirm that you can view the directory contents of this CD from Explorer. If you can then:
2. Execute this code, changing the drive if needed:

Code: Select all

dim as string drive,s
'
drive="d"
s=dir(drive & ":\*.*",63)
while s<>""       'should list files on drive..
   print s
   s=dir()
wend
'
print:print "Sleeping to Exit"
sleep

Forget the harddrive stuff, you've eliminated the write prob. Can you read the CD from Explorer, does the code above work.

If not then please you have to provide more info. What version of Windows, what version of the FreeBASIC compiler (these questions should be in a FAQ, someone may tell us that they are).

There isn't any reason that fb can't get a directory listing from any device that Explorer can. If you are requesting file attributes that don't exist, that can be a prob.

ETA: file attribute mask "63", should return something..
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Postby bcohio2001 » Mar 11, 2007 11:35

Tried your little code, it worked fine, returned all files and folders on the CD.
Then tried to use '16' to replace the 63. It returned nothing.

Adapted your code to return the attributes.
Regular files returned a 1
Folders........returned a 17

I thought that Dir( would return it if the bit was set. 17 = 16 and 1
16 - dir
1 - read only

Return to “General”

Who is online

Users browsing this forum: Josep Roca and 18 guests