Results 1 to 3 of 3

Thread: Extract File Management Info

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    3

    Extract File Management Info

    I need to extract the exact same items that a file search finds and parses - file name, full path (without file name) and date - and send these items to sql to populate a simple 3-field table.

    We have a directory that is updated daily and I need a sql table that reflects the updated list of files, folders, and dates - this information is used to provide easy access to the files through a simple web interface. The directories are not always the same, and the depth of the sub-directories may change also.

    This needs to be an easy procedure which can be run as a timed procedure on a pc at night - with absolutely no interaction from a person.

    Does anyone have any ideas?

    Here is some vba code I have that works to collect some of the correct info inside Excel - but I need it to be standalone.

    Sub IndexFiles()
    With Application.FileSearch
    .LookIn = "C:\student\ipao\data"
    .FileType = msoFileTypeAllFiles
    .SearchSubFolders = True
    .Execute
    End With
    cnt = Application.FileSearch.FoundFiles.Count
    For i = 1 To cnt

    ' sets the cell reference for each result - a1, a2 a3 a4...
    Rng = "A" & i
    Range(Rng).Value = Application.FileSearch.FoundFiles.Item(i)

    Rng = "B" & i
    Range(Rng).Value = FileDateTime(Application.FileSearch.FoundFiles.Item(i))


    Next i
    End Sub

    Thanks so much (ahead of time) for your help!
    Last edited by Bauerchick; May 27th, 2004 at 11:52 AM.
    Thanks!~
    Bauerchick

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Do something like this:

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         AddFilesToDB("C:\Temp")
    3.     End Sub
    4.  
    5.  
    6.     Private Sub AddFilesToDB(ByVal strPath As String)
    7.         Dim d As System.IO.Directory
    8.         Dim f As System.IO.File
    9.         Dim sFiles() As String
    10.         Dim sDirs() As String
    11.         Dim sCurr As String
    12.         Dim sPath As String
    13.         Dim sFile As String
    14.         Dim dtTime As DateTime
    15.         sFiles = d.GetFiles(strPath)
    16.         For Each sCurr In sFiles
    17.             sPath = sCurr.Substring(0, sCurr.LastIndexOf("\"))
    18.             dtTime = f.GetCreationTime(sCurr)
    19.             sFile = sCurr.Substring(sCurr.LastIndexOf("\") + 1)
    20.             Debug.WriteLine(sPath & sFile & dtTime)
    21.             'Add these values to your database table
    22.         Next
    23.         sDirs = d.GetDirectories(strPath)
    24.         For Each sCurr In sDirs
    25.             AddFilesToDB(sCurr)
    26.  
    27.         Next
    28.     End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    3

    Thanks... but...

    (big smile parts face)
    Thank you for the code - I will try it later today...
    However, can you tell me where I set the directory that I want it to inventory? It should be something that is easily editable so if the files move somewhere else, it will be easy to adjust and keep going.
    Thanks!~
    Bauerchick

Posting Permissions

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



Click Here to Expand Forum to Full Width