Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file search via macro

Status
Not open for further replies.

Christian22

IS-IT--Management
May 3, 2005
6
DE
hi,

I have a new problem.
Now I need a macro, which search for some files (I already have the filenames ). I only need the commands to find these files. - I'm using Microsoft Project 98.

Thx
 
The VB command you're looking for is DIR.

You'll need to set up two loops, one recursive loop to traverse the directory structure and one non-recursive one to sequentially test each filename.

looper_dir startingpath


sub looper_dir (stpath)

for each item in the stpath
If the item is a sub-directory then
looper_dir (stpath & "\" & sub-directoryname)
else
if the item is a file and filename is a match then
store path and filename, date, size in array
end if
end if
next

end sub

Since the same name can be used on multiple files stored in multiple locations, you'll need to check the array contents when you exit to determine if you found the file and, if found, which one you'll use. And, of course, you'll also need a check to determine if you found all files.

Since you could be on a machine on a network you'll have to consider various drives and you'll have to handle a variety of error conditions if you don't have access privs to the drives and/or folders.
 
Glad I could help. Perhaps you might consider posting it here so that others can learn from your experiences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top