Find Files Macro
Find Files Macro
(OP)
Anyone know of a way I can search a server for a file with a macro. I have to iterate through a large number of folders and sub folders to find my files. I would like to write a macro to iterate through them for me and open or give me options of files to open. I would like to do this in a macro simply so that I do not have to use MS search and then have to open the files via MSExplorer. Any Ideas?????????
Thanks
Thanks






RE: Find Files Macro
I don't you could do this from a standalone SW macro. This would have to be a external program to do that... IMO
Regards,
Scott Baugh, CSWP
http://www.3dvisiontech.com
http://www.scottjbaugh.com
If you are in the SW Forum Check out the FAQ section
To make the Best of Eng-Tips Forums FAQ731-376
RE: Find Files Macro
http://www.mtcnet.net/~arlin/swx_files/open_file.zip
In the macro, you type in the part number (file name) and it automatically figures out where the file should be located and opens it.
It requires that the file be organized in some sort of logical manner so that an algorithm can be written to figure out the folder from the file name. Feel free to take a look and modify it to your needs.
RE: Find Files Macro
I have about 100-150 directories containing thousands of parts.
When a shop employee calls with a question on a drawing I have to hunt and peck for the SLDDRW or use MS Search which is slow due to the amount of files to sift through, not to mention the server is mac based (not really relevant though). But it would be nice when the phone rings to click a button in SW and type in the Part Number and the drawing opens for me. We use a database system on our macs that allow me to pull the DXF files easily but we do not fully dimension them so usually we have to open the SLDDRW to answer questions.
RE: Find Files Macro
RE: Find Files Macro
RE: Find Files Macro
RE: Find Files Macro
RE: Find Files Macro
RE: Find Files Macro
RE: Find Files Macro
Glad to help. If you need any more help or have any questions, let me know.
RE: Find Files Macro
CODE
Function GetAllFiles(ByVal path As String, ByVal filespec As String, _
Optional RecurseDirs As Boolean) As Collection
Dim spec As Variant
Dim file As Variant
Dim subdir As Variant
Dim subdirs As New Collection
Dim specs() As String
' initialize the result
Set GetAllFiles = New Collection
DoEvents
' ensure that path has a trailing backslash
If Right$(path, 1) <> "\" Then path = path & "\"
' get the list of provided file specifications
specs() = Split(filespec, ";")
' this is necessary to ignore duplicates in result
' caused by overlapping file specifications
On Error Resume Next
' at each iteration search for a different filespec
For Each spec In specs
' start the search
file = Dir$(path & spec)
Do While Len(file)
' we've found a new file
file = path & file
GetAllFiles.Add file, file
fCount = fCount + 1: fcountlbl.Caption = fCount & " files found..."
' get ready for the next iteration
file = Dir$
Loop
Next
' first, build the list of subdirectories to be searched
If RecurseDirs Then
' get the collection of subdirectories
' start the search
file = Dir$(path & "*.*", vbDirectory)
Do While Len(file)
' we've found a new directory
If file = "." Or file = ".." Then
' exclude the "." and ".." entries
ElseIf (GetAttr(path & file) And vbDirectory) = 0 Then
' ignore regular files
Else
' this is a directory, include the path in the collection
file = path & file
subdirs.Add file, file
End If
' get next directory
file = Dir$
Loop
' parse each subdirectory
For Each subdir In subdirs
' use GetAllFiles recursively
For Each file In GetAllFiles(subdir, filespec, True)
GetAllFiles.Add file, file
Next
Next
End If
End Function
RE: Find Files Macro
RE: Find Files Macro
I see you’re already set to go on your new macro. (Please do not take me wrong.) I love writing macros. One of the things I always forget is, do not spend more time writing a macro than it saves. I have spent 80 hours writing a macro that saved 1 hour per week. I would do it again because of the frustration it saved.
With that being said, I would recommend looking into getting SolidWorks PDM\Works. We use it and just love it. Drawings are fast to find, it keeps history and easy to use. We have saved thousands of dollars restoring files that someone has messed up. Once an assembly is in the PDM it does not get lost. We have lost lots of files while keeping them on the network.
Good luck with your macro.
Bradley
RE: Find Files Macro
RE: Find Files Macro