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

Files and Directories

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

List All Files Older Than...

Keywords: 	 List All Files Older Than...  UDFListAllFilesOlderThan

;This UDF will return a listing of all files under any directory
;that are older than the date specified
;Use c:\ for the root.

#DefineFunction UDFListAllFilesOlderThan(list,fromdir,CutOffDate)   
    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 parameters just in case
    if strsub(fromdir,strlen(fromdir),1) != "\" then fromdir=strcat(fromdir,"\")
        
    ;copy files in this directory
    templist=FileItemPath("*.*")
    fcount=ItemCount(templist,@tab)
    for ff=1 to fcount
       thisfile=ItemExtract(ff,templist,@tab)
       if FileTimeGetEx(thisfile,2) < CutOffDate
           list = StrCat(list,@tab,thisfile)
       endif
    next ff
    
    ;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,"\")       
       list = UDFListAllFilesOlderThan(list,fullfromdir,CutOffDate)
    next xx
    return StrTrim(list)
#EndFunction

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CutOffDate = "2002:01:01:00:00:00"; Jan 1, 2002
StartDir="C:\temp"   
list = UDFListAllFilesOlderThan("",StartDir,CutOffDate)
IntControl (63, 0, 0, 1000, 950)
AskItemList(StrCat("Files Older Than ",CutOffDate),list,@tab,@unsorted,@single)
Message("All","Doned")




Article ID:   W15753
File Created: 2004:04:27:10:50:04
Last Updated: 2004:04:27:10:50:04