Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


UDF to List All Files in a Directory

Keywords:   UDF list all files UDFListAllFiles

;This UDF will make a listing of all fines under any directory.
;Use c:\ for the root.

#DefineFunction UDFListAllFiles(handle,fromdir)
    Terminate(DirExist(fromdir)==@FALSE,"Eeep","From directory does not exist")
    ;make sure we have a full path or a UNC
    fromtest=StrIndex(fromdir,":",0,@FWDSCAN) + (StrSub(fromdir,1,2)=="\\")
    Terminate(fromtest==0,"Eeep","Full path must be specified for FromDir")
    
    DirChange(fromdir)
    ;clean up passed paramters just in case
    If StrSub(fromdir,StrLen(fromdir),1) != "\" Then fromdir=StrCat(fromdir,"\")
        
    ;copy files in this directory
    FileWrite(handle,StrCat("**** Checking ",fromdir))
    list=FileItemPath("*.*")
    If list!="" Then FileWrite(handle,StrReplace(list,@TAB,@CRLF))
    
    ;get list of subdirectories
    dirlist=DirItemize("*.*")
    count=ItemCount(dirlist,@TAB)
    ;Process each subdirectory
    For xx=1 To count
       thisdir=ItemExtract(xx,dirlist,@TAB)
       fullfromdir=StrCat(fromdir,thisdir,"\")       
       UDFListAllFiles(handle,fullfromdir)
    Next
    Return
#EndFunction

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

StartDir="C:\temp"   
Handle=FileOpen("C:\temp\list.txt","WRITE")

UDFListAllFiles(handle,StartDir)
FileClose(handle)
Message("All","Doned")