|
<< Click to Display Table of Contents >> Navigation: Programming Mechworks PDM > DBWCommandShell > Object Reference > FileScan Methods > COM API to find files |
MechWorks MWScriptGUI Scripting Utility Object
A COM API has been made available to scan a directory and all it's subdirectories and look for file by name.
This function is used by the Registration Wizard to find cad documents.
The function is optimized for speed and you can expect to get a result of medium to large scans (hundreds of subdirectories) in less than one minute.
The function is available for the object DBWSharedComponents.FileScan
The equivalent of the function declaration in VB is
scanDirectory (dir as String, extensionList as String, optional showWindow as boolean = true, TraversingDepth as int) as Variant
scanDirectory1(dir as String, extensionList as String) as Variant
scanDirectory2(dir as Obejct, extensionList as String, optional showWindow as boolean = true) as Variant
It's possible to use different methods depending on the parameters provided.
dir |
Full path of the directory to be scanned. All its subdirectories will be scanned. |
|---|---|
extensionList |
List of the search patterns separated by ';' as in "*.sldprt;*.sldasm;*.sldprt" |
showWindow |
Display scan progress |
TraversingDepth |
Search depth for the subfolder traversing |
The function returns a Variant (SafeArray) with the list of full paths of the files found
Note that though the most obvious use of this object is to find files by extension, you can specify DOS-like search patterns such as "*handle*" or "sw*.doc;sw*.xls".
The dir parameter indicating the directory to be scanned could or could not end with the character '\'
This is a valid example of a script that scans the directory 'c:\program files' and displays the files found one by one. The file names are displayed in message boxes for the sake of simplicity; if you run it mind that you might find hundreds of files and would likely have to kill the script process not to see hundreds of message boxes and have to click them one by one.
Set scan = CreateObject("DBWSharedComponents.FileScan")
dim arrayOfFiles
arrayOfFiles = scan.scanDirectory("c:\program files\","*.sldprt;*.sldasm;*.slddrw")
msgbox "Found " + cstr(ubound(arrayOfFiles) + 1) + " documents",,"Search completed"
' display the files found in message boxes, one by one
for i = 0 to ubound(arrayOfFiles)
msgbox cstr(arrayOfFiles(i))
next
set scan = nothing
During the scan the object can display optionally on screen a window that shows the current directory being scanned and the files found so far:

Mind that in the current version the scan cannot be canceled, so if you write test scripts you'd better avoid huge scans such as "c:\"