Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Archiving

Status
Not open for further replies.

Budgie69

Technical User
Jul 12, 2001
47
AU
Hi Guys

Hope somebody can help out here;

here is the problem

I need to move files older than a particular date from a data share we have, eg all 2003 files. However when i move these files i need to ensure that same folder path is kept to the destination location.

Can this be done, whats the best util to use

thanks in advance.
 
I believe that you can do this with Robocopy. I know you can copy files preserving the path, and I believe that you can use date criteria as well. It's the moving or deleting of the original copy that I'm not 100% sure about. Not only that, but Robocopy can preserve the ACLs on the files.

I actually wrote a script awhile back that would generate a file list to be archived similar to that, but I'm having trouble adapting it to do the file moving. Because it recurses subdirectories there's a lot of checking that needs to be done for the presence of directories before it can copy them.

At any rate, if I get it finished today or this weekend I'll post it for you.
 
Yes you can use robocopy for this. It will do a move or a copy depending on what switches you use. It can use a date as part of it's criteria.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Yeah, I've sean that before. Made me feel dirty looking at it. Never have used it. I've always found the command line to be as awsome tool, because there wasn't a GUI to deal with.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Command line? Real men roll their own! :)

Code:
strSourceDir = "C:\somepath" ' Set this to the directory you archive from
strDestDir = "C:\archive" ' Set this to the directory you archive to

intCutoffAge = 0 ' Set this to the age in days that you want to use for the cutoff

Set objFSO = CreateObject("Scripting.FileSystemObject")

CrawlTree strSourceDir

Sub CrawlTree(strSourceDir)
    Dim objFolder, arrFolders, objFiles, Item, Item2
    Set objFolder = objFSO.GetFolder(strSourceDir)
    Set arrFolders = objFolder.SubFolders
    Set objFiles = objFolder.Files
    
    intPathLength = Len(strSourceDir)
    intPathLength = intPathLength -2
    strDestFolder = strDestDir & Right(strSourceDir,intPathLength)
    Wscript.Echo "strDestFolder = " & strDestFolder
    If Not objFSO.FolderExists(strDestFolder) Then
        arrPath = Split(strDestFolder,"\")
        strNewFolder = ""
        For i = 0 to Ubound(arrPath)
            Wscript.Echo arrPath(i)
            strNewFolder = strNewFolder & arrPath(i) & "\"
            Wscript.Echo strNewFolder
            If Not objFSO.FolderExists(strNewFolder) Then
                MakeFolder = objFSO.CreateFolder(strNewFolder)
                Wscript.Echo strNewFolder & " created!"
            Else
            End If            
        Next
    Else
    End If
    
    ' Get all sub-folders in this folder
    For Each Item In arrFolders
        CrawlTree(item)
    Next
    Item2 = 0

    'Scan through  the files collection, find files older than cutoff age and moves them.
    For Each Item2 in objFiles
    Dim strAccessDate, strCreatedate, objFileName, intDaysOld
    Set objFileName = objFSO.GetFile(Item2)
    strAccessDate = objFileName.DateLastAccessed
    intDaysOld = DateDiff("d", strAccessDate, Now)
    If intDaysOld > intCutoffAge Then
        Wscript.Echo Now & " -- " & objFileName.Path & " is " & intDaysOld & " days old."
        strPathName = objFilename.Parentfolder
        intPathLength = Len(strPathName)
        intPathLength = intPathLength -2
        strMovePath = strDestDir & Right(strPathName,intPathLength) & "\"
        Wscript.Echo "objFilename.Path = " & objFilename.Path
        Wscript.Echo strMovePath
        objFileName.Move (strMovePath)
	    Wscript.Echo objFileName.Path & " was archived to " & strDestDir
    Else
    End If
    Next
End Sub
 
The biggest problem I've seen with the GUI (at least when I last looked at it), was that it only allowed for a single source and destination. I prefer to batch it and do all the sources and destinations in one batch file. Much simpler for us lazy types.

Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP
Want to know how email works? Read for yourself -
 
I agree robocopy from the command line is far more flexible i just hadn't come accross the GUI before, as it's been a requested feature in the past i thought it was worth a mention.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top