Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2004
    Posts
    3

    Unanswered: Directory Structure

    Hello Forum!
    I want to be able to capture the names of files on a specified directory. Take the name and extensions of those files and put them in a table with the attributes set to hyperlink.

    I have tried using freeware software for exporting the directory tree but so far I have not been able to find one that will generate a file suitable for importing into Access.

    I don't care about file size or anything else. Just the stupid name of the file.

    Thank you much!!!

  2. #2
    Join Date
    Jan 2004
    Location
    Islamabad, Pakistan
    Posts
    97
    Here is a sample function with directory path as argument. Call this function or customize it as required...

    Function ShowFilesNames(TxtDirPath As String)
    Dim FileName
    'Sets the Path
    FileName = Dir(TxtDirPath) ' Retrieve the first entry.
    Do While FileName <> "" ' Start the loop.
    ' Ignore the current directory and the encompassing directory.
    If FileName <> "." And FileName <> ".." Then
    Debug.Print FileName ' Display entry in debug window - just as an example
    ' here you can put your code to put this value into a database field
    End If
    FileName = Dir ' Get next entry.
    Loop
    End Function


    -regards
    Saqib

  3. #3
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    Can anyone help me with this?

    I don't understand how this code works and its very similar to what I want. If someone can give me an explanation it would really help.

    How would you get it to go to a specific directory? or even a specific file?

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Here is an example using the function of [ Mr Saqib ]
    Attached Files Attached Files

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    By the way try to look up FileSearch or Application.FileSearch in the help....
    It is more efficeint to use this FileSearch object....

  6. #6
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,468
    Provided Answers: 10
    Here


    some code i wrote to read cd and put the filename name into the database


    Code:
    Option Compare Database
    Public ad, CDNAME, FullPath, CDCOUNT
    Const CDPATH = "D:"
    
    
    Sub open_Close()
    Dim oWMP As Object
    Dim colCDROMs As Object
    
    Set oWMP = CreateObject("WMPlayer.OCX.7")
    Set colCDROMs = oWMP.cdromCollection
    
    If colCDROMs.Count >= 1 Then
            For i = 0 To colCDROMs.Count - 1
                    colCDROMs.item(i).Eject
            Next ' cdrom
    End If
    End Sub
    
    
    Sub Read_CD()
        Dim FSO, Folder, SubFolders, Drive
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set Drive = FSO.GetDrive(CDPATH)
        
        'Do Until Drive.isready
        
        'Loop
        
        If Drive.isready Then
            CDNAME = Drive.VolumeName
            Form_Main.CDNAME.Caption = CDNAME
            aa = DCount("cdname", "CD", "cdname ='" & CDNAME & "'")
            If aa = 0 Then
            CDCOUNT = 0
                Set Folder = FSO.GetFolder(CDPATH)
                Set SubFolders = Folder.SubFolders
                If SubFolders.Count <> 0 Then
                    For Each SubFolder In SubFolders
                        Call GenerateFolderInformation(SubFolder)
                    Next
                End If
                Else
        Beep
        Form_Main.CDNAME.Caption = "CD DONE"
            End If
        End If
        Set FSO = Nothing
        Set Drive = Nothing
        Call open_Close
        
    End Sub
    
    Sub GenerateFolderInformation(Folder)
       Dim S
       Dim SubFolders
       Dim SubFolder
       Dim Files
       Dim File
       Dim FileName
       
    Dim db As Database
    Dim rs As Recordset
    Set db = CurrentDb
    Set Files = Folder.Files
    
       If Files.Count <> 0 Then
       'Set rs = db.OpenRecordset("cd", dbOpenDynaset, dbSeeChanges)
        Set rs = db.OpenRecordset("cd")
         For Each File In Files
             FileName = Mid(File, 3, Len(File))
             adstart = InStr(2, FileName, "\")
             ad = Mid(FileName, adstart + 1, 7)
             rs.AddNew
             rs.Fields("ad") = UCase(ad)
             rs.Fields("cdname") = UCase(CDNAME)
             rs.Fields("Fullpath") = UCase(FileName)
             'rs.Fields("IDate") = Date
             rs.Update
             CDCOUNT = CDCOUNT + 1
             'Beep
               Next
         rs.Close
         Form_Main.CDCOUNT.Caption = CDCOUNT
         Set rs = Nothing
       End If
       
        Set SubFolders = Folder.SubFolders
       
        If SubFolders.Count <> 0 Then
          For Each SubFolder In SubFolders
          ad = SubFolder.Name
             Call GenerateFolderInformation(SubFolder)
          Next
       End If
    Set db = Nothing
    Set File = Nothing
    Set SubFolder = Nothing
    End Sub
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

  7. #7
    Join Date
    Oct 2003
    Location
    London
    Posts
    341

    Thumbs up

    Wasalaam hammbakka.

    Thanks for that zip file this is exactly a starting point I need. I will make good use of this.

    Also, Myle - thanks for your input. I'm going to try hammbakka's way but if I fail with that I'll attempt your way.

    Thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •