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

Directory and Deltree UDFs

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

UDF to List All Files in a Directory

Keywords:   UDF list all files UDFListAllFiles

;This UDF will make a listing of all files 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")





Article ID:   W15747
File Created: 2008:04:11:11:45:26
Last Updated: 2008:04:11:11:45:26