How to Search for Multiple File Types
Keywords: multiple file types
Question:
Can somebody tell me what is wrong with the following??:hand=srchInit("c:\","*.txt|*.dll","","",16)I am trying to seach for multiple file types. Pretty easy huh??Answer:
Sorry. Srch can only search for one file mask. *.txt and *.dll will not work.There are two possible workarounds
- Two separate searches, one for *.txt and a second for *.dll.
I kind of recommend this one.
- Search for *.* and have code after the srchNext that looks like...
fn=srchnext(handle) if fn == "" then break fnext=strlower(FileExtension(fn)) if fnext!="txt" && fnext!="dll" then continueAnother Example of Searching for Multiple File Types
Question:
I need to xcopy all the folders containing .doc and .xls files to the backup folder in NT Server. Even if several .doc or .xls files are located in the same folder, xcopy command line must appear only once.The script works fine. Only that it locates folders that does not contain .Doc and .xls files.
Have any clues?
The script:
AddExtender("wsrch34I.dll") Dir=DirGet( ) TopSrchDir = 'C:\' nHandle = srchInit(TopSrchDir,"*.doc","",0,48) while 1 Path=srchNext(nHandle) PathTrunk=StrSub(Path,4,-1) if Path=="" then break ;pause("Found",xxx) CommandLine="xcopy %Path%*.* \\ServerNt\Backup\%PathTrunk%*.* /c /q /h /r /m /e /I" fp=FileOpen("temp876.num","WRITE") FileWrite(fp,CommandLine) FileClose(fp) FileAppend("temp876.num","%PathProg%Command.bat") FileAppend("temp876.num","%Path%%LF1%") FileDelete("temp876.num") endwhile srchFree(nHandle) Run("notepad.exe","%Dir%Command.bat")Answer:
- srchInit cannot take multiple wildcards
- Don't need flag +32 That will return every directory searched
- Here is my try at the problem:
AddExtender("wsrch34I.dll") Dir=DirGet( ) TopSrchDir = 'C:\' nHandle = srchInit(TopSrchDir,"*.*","",0,16) OldPath="XXXX-:GARGAGE:-XXXX" while 1 TheFilename=srchNext(nHandle) if TheFilename=="" then break ext=StrLower(FileExtension(TheFilename)) if ext != "doc" && ext != "xls" then continue path=FilePath(TheFileName) PathTrunk=StrSub(Path,4,-1) if stricmp(PathTrunk,OldPath) == 0 then continue OldPath=PathTrunk ;pause("Found",xxx) CommandLine="xcopy %Path%*.* \\ServerNt\Backup\%PathTrunk%*.* /c /q /h /r /m /e /I" fp=FileOpen("temp876.num","WRITE") FileWrite(fp,CommandLine) FileClose(fp) FileAppend("temp876.num","%PathProg%Command.bat") FileAppend("temp876.num","%Path%%LF1%") FileDelete("temp876.num") endwhile srchFree(nHandle) Run("notepad.exe","%Dir%Command.bat")
Article ID: W12555Filename: How to Search for Multiple File Types.txt