Reading File Structure from a CD ????

Robert88

Robbie
Local time
Tomorrow, 07:10
Joined
Dec 18, 2004
Messages
333
I was wondering if it is possible to be able to read a CD directory structure in as maybe a variable and ultimately reading it into a field in a table?

If it is possible would more than likely chop and cut directory path up into smaller bits as the paths have a fixed length and each substructure has the same structural length.

Ultimately use the info to create labels for CD Jackets, since I have a lot of CD's hence the reason for my queastion above.

Look forward to any advice.
 
Last edited:
Thanks for the suggestion but this would appear more for music CD's. Since the CD's I have contain data under a set folder structure it would appear to be missing info that this program requires in order to interogate the folder structure on the CD.

Any other suggestion that anyone may have would be most helpful.
 
I suppose as an example, my DVD drive is D:\ and an example of a folder path on one CD is "PROJ9\13245\60CFGHJY\CDP\R1AA\FGP".

Part of the CD label should contain this path and within this folder are FGP files, OR1AA000.fgp, OR1AA001.fgp........ to 0R1AA023.fgp.

So the label would consist of the path above and parts being used for other parts of the label and in addition the label would consist of one line indicating the first and last of the fgp files like, "0R1AA000.fgp - 0R1AA023.fgp".

The label will also consist of many other paths and contents of folders but if I work on this one first the rest will either be similar or the same. But in order to read this path in I am unaware. Any help would be appreciated.
 
Scan a cd
The following code will scan a CD for you, You will have to ad additional code to put it into a databse

Dim fso As Object
Dim flds As Folders
Dim fld As Folder

Private Sub cmdScan_Click()
Dim drvs As Drives
Dim drv As Drive
Set fso = CreateObject("Scripting.FileSystemObject")
Set drvs = fso.Drives

For Each drv In drvs
If drv.DriveLetter = "D" Then
Set fld = fso.GetFolder(drv.Path)
SearchTheFolder fld
End If

Next

End Sub

Sub SearchTheFolder(myFld As Folder)
Set flds = myFld.SubFolders
SearchTheFiles myFld.Files
For Each fld In flds
SearchTheFolder fld
Next
End Sub

Sub SearchTheFiles(fls As Files)
For Each fil In fls
MsgBox fil.Name
Next
End Sub
 
Hey guys, sorry for taking so long to respond but been in my sick bed with flu for a week, sorry.

Thanks for the code Mike, and thanks for the suggestions that followed Pat, I appreciate it. I have tried both with no success.

I get an error "User-defined type not defined"

Any further help would be appreciated, the code for placing it in a table would also be appreciated as this would be handy.

Robert88
 
No I did not, was not sure which one to use. Microsoft Scriptlet Library?

Currently I have References;

1. Visual Basic For Applications;
2. Microsoft Access 11.0 Object Library;
3. OLE Automation;
4. Microsoft DAO 3.6 Object Library;
5. Microsoft ActiveX Data Object 2.5 Library;

selected, but not sure which reference you refer to in relation to scripting library.

Your help would be appreciated, by the way I am using Microsoft Office Access 2003 with SP1.

Robert88
 
Last edited:
Look for
Microsoft Scripting Runtime

HTH

Peter
 
Thanks Bat17. I also have to thank Pat as he guided us both there.

That has placed the content of files one at a time into a message box.

How do I go about placing the folder path and file into a table?

Sorry for being a nusiance, great work so far....

Or if you can suggest a good book around this topic I am open to a good book, just seems to be so many on the market. Happy to take suggestions for a book in relation to this issue. I already have four programming books on Access and none cover this issue.
 
Last edited:
I dug a little deeper into my access programming books and stumbled across this code which after a few modifications allows me to search for all *.fgp files but cannot seem to get it to work.

Sub FileSearch1XP()

'Search the CD and all subfolders
'on the d drive of the CD's for *.fgp files
With Application.FileSearch
'Start a new Search
.NewSearch
'Set Search Criteria
.LookIn = "D\"
.FileName = "*.fgp"
.SearchFolders = True
End With

With Application.FileSearch
'Execute the search
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & "file(s) found."
'Display name of all found files
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
'If no files found, say so
MsgBox "There were no files found."
End If
End With

End Sub

In addition I am using the "Microsoft Office 11.0 Object Library" reference.


Can anyone help as to why it is not working?

Robert88
 
Last edited:
Robert88 said:
How do I go about placing the folder path and file into a table?
Check this sample out... Browse [Find a directory or file]

It will show you how to fill a table with the path and file name for every file in a specific directory. You can modify the code to only search for a specific file type and/or file name.
 
Thanks for everyone's help

Thank you all for your help,

I finally got there......

Code:
Private Sub CmdReadMedia_Click()

    Dim Drivename As String
   
    Dim dbs As Database
    Dim Mysize
    Set dbs = OpenDatabase("C:\CD Labeller - Microsoft Access 2003\CDlabel.mdb")
    
    'Clear the tblFilename table before scan is added.
    dbs.Execute "DELETE * FROM tblFilename;"
    
    Set fs = Application.FileSearch
    With fs
	'This is of course assumes that your CD Drive is in D:\ 
        .LookIn = D:\
        .FileName = "*.*"
        .SearchSubFolders = True
        If .Execute(SortBy:=msoSortByFileName, _
                SortOrder:=msoSortOrderAscending) > 0 Then
            MsgBox "There were " & .FoundFiles.Count & _
                " file(s) found."
            For I = 1 To .FoundFiles.Count
                Mysize = FileLen("" & .FoundFiles(I) & "")
                'send data to a message box for test purpose.
                'MsgBox .FoundFiles(I)
                
                'send data from Sql to variable Sql.
                SQL = "INSERT INTO tblFilename" & _
                "(fldFieldname, fldFileSize) Values " & _
                "('" & .FoundFiles(I) & "', '" & Mysize & "');"
                'send data from sql to message box
                'MsgBox Mysize
                'send data form Sql to database tblFilename.
                dbs.Execute SQL
                
             Next I
                MsgBox "The folderpath and filenames have been written to table tblFilename succesfully."
                'close database connection.
                dbs.Close
        Else
            MsgBox "There were no files found."
        End If
    End With


End Sub
 

Users who are viewing this thread

Back
Top Bottom