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.

DelTree and Xcopy

 Keywords:  DelTree xcopy recursive copy 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)
    ;optional mod instead of above line use following to remode r/o bit
    ;FileCopyAttr( strcat(fromdir,"*.*") , strcat(todir,"*.*") , 0, "r")




    ;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
   Terminate(DirExist(dir)==@FALSE,"Eeep","Directory does not exist")
   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
File Created: 2004:11:23:09:16:12
Last Updated: 2004:11:23:09:16:12