WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Searcher
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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

  1. Two separate searches, one for *.txt and a second for *.dll.

    I kind of recommend this one.

  2. 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 continue
    

Another 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:

  1. srchInit cannot take multiple wildcards
  2. Don't need flag +32 That will return every directory searched
  3. 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:   W12555
Filename:   How to Search for Multiple File Types.txt
File Created: 2001:03:01:15:34:02
Last Updated: 2001:03:01:15:34:02