|
-
May 27th, 2004, 11:40 AM
#1
Thread Starter
New Member
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
-
May 27th, 2004, 11:58 AM
#2
Do something like this:
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddFilesToDB("C:\Temp")
End Sub
Private Sub AddFilesToDB(ByVal strPath As String)
Dim d As System.IO.Directory
Dim f As System.IO.File
Dim sFiles() As String
Dim sDirs() As String
Dim sCurr As String
Dim sPath As String
Dim sFile As String
Dim dtTime As DateTime
sFiles = d.GetFiles(strPath)
For Each sCurr In sFiles
sPath = sCurr.Substring(0, sCurr.LastIndexOf("\"))
dtTime = f.GetCreationTime(sCurr)
sFile = sCurr.Substring(sCurr.LastIndexOf("\") + 1)
Debug.WriteLine(sPath & sFile & dtTime)
'Add these values to your database table
Next
sDirs = d.GetDirectories(strPath)
For Each sCurr In sDirs
AddFilesToDB(sCurr)
Next
End Sub
-
May 27th, 2004, 01:13 PM
#3
Thread Starter
New Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|