Wilson WindowWare Tech Support

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


DelTree and Xcopy

 Keywords:  DelTree xcopy recursive delete


#DefineFunction UDFXcopy(fromdir,todir)
    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)=="\\")
    totest=strindex(todir,":",0,@fwdscan) + (strsub(todir,1,2)=="\\")
    Terminate(fromtest==0,"Eeep","Full path must be specified for FromDir")
    Terminate(totest==0,"Eeep","Full path must be specified for ToDir")
    
    DirChange(fromdir)
    ;clean up passed paramters just in case
    if strsub(fromdir,strlen(fromdir),1) != "\" then fromdir=strcat(fromdir,"\")
    if strsub(todir,strlen(todir),1) != "\" then todir=strcat(todir,"\")
    
    ;Make sure target directory exists
    if DirExist(todir)==@FALSE then DirMake(todir)
    
    ;copy files in this directory
    FileCopy( strcat(fromdir,"*.*") , strcat(todir,"*.*") , 0)
    
    ;get list of subdirectories
    dirlist=DirItemize("*.*")
    count=ItemCount(dirlist,@tab)
    ;Preocess each subdirectory
    for xx=1 to count
       thisdir=ItemExtract(xx,dirlist,@tab)
       fulltodir=strcat(todir,thisdir,"\")
       fullfromdir=strcat(fromdir,thisdir,"\")
       UDFXcopy(fullfromdir,fulltodir)
    next
    return
#EndFunction

#DefineFunction UDFDELTREE(dir)
   ;Include hidden files
   IntControl(5,1,0,0,0)
   ;change to target directory
   DirChange(dir)
   topdir=DirGet()
   ;Delete all files in target
   FileAttrSet("*.*","rash")
   FileDelete("*.*")
   ;Get list of subdirectories
   dirlist=DirItemize("*.*")
   ;Process list
   dircount=ItemCount(dirlist,@tab)
   for xx=1 to dircount
      thisdir=ItemExtract(xx,dirlist,@tab)
      UDFDELTREE(thisdir)
   next
   ;bump up one directory level
   DirChange("..")
   ;remove that directory
   DirAttrSet(dir,"rash")
   DirRemove(dir)
#EndFunction



UDFXcopy("C:\temp","c:\tempx")
Message("","Xcopy complete")

UDFDelTree("c:\tempx")
Message("","Deltree complete")

Message(0,0)






Article ID:   W14748
Filename:   DelTree and Xcopy.txt