After two weeks of searching, I'm resorting to getting help. I want to be able to find a lost folder, whether or not it has any files in it. I want to be able to specify the drive or path in which to search and have the procedure return to me all the (parent) paths in which the particular folder name was found. I'd like to be able to exclude certain folder levels from the search results if possible. And, not as importantly, I'd like to be able to use wildcards in the folder name if possible. The reason for this is because we have thousands of clients, each of whom have the same setup of subfolders. Occasionally, a user will mistakenly drag and drop a client's subfolder who-knows-where. I need to be able to find it. For example:
On Drive H: among other folders we have a folder for each letter of the alphabet. Then under each letter, we have a subfolders for each Client whose name begins with that letter. Then under each client we have subfolders that could be called something like ClientInfo, ClientBusiness, Legal, Notes, etc. A path could look like: H:\Clients\S\Smith\ClientInfo. Sometimes a Client folder with its subfolders is mistakenly dragged and dropped. Sometimes just a subfolder is mistakenly dragged and dropped. It could be dropped anywhere, as you can imagine. Since every client has a folder named Legal, for example, I don't need to see the thousands of Clients with a folder named Legal. I only need to see the paths at some other level than the Client folder level or on some other drive. That's why the Vista search facility is not what I need. I'd like to be able to specify, Give me all the folders named Legal that are not immediately under a Client folder. It might be under another Client's Legal Folder or ClientInfo folder. It might be under a letter folder. It might be on another drive, say, G:.
I have included below code that does something similar to this for finding lost files, but I cannot find a comparable property or method to the Application.FileSearch property. I've tried using the Dir function, but this requires me to be too specific regarding the path to search and seems to require searching for a file rather than a folder.
We have Vista Business on our machines with MS Office 2003 Pro. I want to build this search into our Access 2003 application for the users.
I'm hoping someone has a solution.
Thank you!
Code:
sSearchName = Trim(Forms!frmFindFile![SearchName])
sSearchPath = Forms!frmFindFile![SearchPath]
Set fs = Application.FileSearch
Set fs2 = CreateObject("Scripting.FileSystemObject")
fs.LookIn = sSearchPath
fs.SearchSubFolders = True
fs.FileName = sSearchName
If fs.Execute() > 0 Then
MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
Filespec = fs.FoundFiles(i)
Set f = fs2.GetFile(Filespec)
s = f.Name & " in " & f.ParentFolder & vbCrLf
' s = s & "Created: " & f.DateCreated & vbCrLf
' s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf
' s = s & "Last Modified: " & f.DateLastModified
sFile = f.Name
spath = f.ParentFolder
sSearchStr = spath
' ----- Add to my table -------------------------
MySet.AddNew
MySet!MyFileName = sFile
MySet!MyPath = spath
MySet.Update
Next i
Else
MsgBox "There were no files found."
End If
On Drive H: among other folders we have a folder for each letter of the alphabet. Then under each letter, we have a subfolders for each Client whose name begins with that letter. Then under each client we have subfolders that could be called something like ClientInfo, ClientBusiness, Legal, Notes, etc. A path could look like: H:\Clients\S\Smith\ClientInfo. Sometimes a Client folder with its subfolders is mistakenly dragged and dropped. Sometimes just a subfolder is mistakenly dragged and dropped. It could be dropped anywhere, as you can imagine. Since every client has a folder named Legal, for example, I don't need to see the thousands of Clients with a folder named Legal. I only need to see the paths at some other level than the Client folder level or on some other drive. That's why the Vista search facility is not what I need. I'd like to be able to specify, Give me all the folders named Legal that are not immediately under a Client folder. It might be under another Client's Legal Folder or ClientInfo folder. It might be under a letter folder. It might be on another drive, say, G:.
I have included below code that does something similar to this for finding lost files, but I cannot find a comparable property or method to the Application.FileSearch property. I've tried using the Dir function, but this requires me to be too specific regarding the path to search and seems to require searching for a file rather than a folder.
We have Vista Business on our machines with MS Office 2003 Pro. I want to build this search into our Access 2003 application for the users.
I'm hoping someone has a solution.
Thank you!
Code:
sSearchName = Trim(Forms!frmFindFile![SearchName])
sSearchPath = Forms!frmFindFile![SearchPath]
Set fs = Application.FileSearch
Set fs2 = CreateObject("Scripting.FileSystemObject")
fs.LookIn = sSearchPath
fs.SearchSubFolders = True
fs.FileName = sSearchName
If fs.Execute() > 0 Then
MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
Filespec = fs.FoundFiles(i)
Set f = fs2.GetFile(Filespec)
s = f.Name & " in " & f.ParentFolder & vbCrLf
' s = s & "Created: " & f.DateCreated & vbCrLf
' s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf
' s = s & "Last Modified: " & f.DateLastModified
sFile = f.Name
spath = f.ParentFolder
sSearchStr = spath
' ----- Add to my table -------------------------
MySet.AddNew
MySet!MyFileName = sFile
MySet!MyPath = spath
MySet.Update
Next i
Else
MsgBox "There were no files found."
End If