Solved

Moving files older than a certain date, but keeping folder structure

Posted on 2012-12-26
6
1,729 Views
Last Modified: 2013-01-03
Hi team

I'm in need of a solution to move files older than 3months off the file server (Server 2008 (Not R2)) onto an external hard drive or network share. I'm by no means skilled in creating script commands, but from what I've read most of the solutions would mean removing the folders etc from the source when moving to the destination which isn't what I want to do.

I'm hoping when the files are moved, the file structure will effectively look identical in both locations making it easier to track down these files if required.

Is this something that can be done, or am I expecting too much?

Cheers
0
Comment
Question by:DTS-Tech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 59

Accepted Solution

by:
Darius Ghassem earned 250 total points
ID: 38722490
You can use something like Robocopy ot Richcopy to copy all data off to another drive both of these have gui so you can use this without scripting

http://blogs.technet.com/b/ken/archive/2009/06/10/build-4-0-216-has-been-posted-to-the-microsoft-download-center.aspx
0
 
LVL 29

Expert Comment

by:becraig
ID: 38722506
This might help:

param ([string] $SourceFolder, [string] $DestFolder,  [string] $DDate);


write-host $sourcefolder
write-host $destfolder
write-host $ddate

if (!(Test-Path $SourceFolder)) 
{ write-host "Source $sourcefolder does not exist!" }
if (!(Test-Path $DestFolder)) 
{ write-host  "Destination $destfolder does not exist!" }


$FileList = Get-ChildItem $SourceFolder -recurse
ForEach ($FileObj in $FileList) {
if ($fileobj.LastWriteTime -lt (Get-Date).AddDays(-$Ddate))
	{
write-host "$FileName = $FileObj.Name"
write-host "$fullpath = $FileObj.FullName"

$FileName = $FileObj.Name
$fullpath = $FileObj.FullName
write-host "$copypath = [regex]::Replace($Fullpath,'$SourceFolder','');"
$copypath = [regex]::Replace("$fullpath", "$SourceFolder",'');
$destpath = $DestFolder + $copypath

Copy-Item "$fullpath" "$destpath"


	}

				}
  

Open in new window

0
 
LVL 29

Expert Comment

by:becraig
ID: 38722513
I forgot to add usage :

script name (whatever you save it as .ps1)
script.ps1 -sourcefolder c:\sourcefolder -destfolder c:\destfolder -ddate40

That should do it.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 29

Assisted Solution

by:becraig
becraig earned 250 total points
ID: 38722742
It seems I had an error in the script I posted:  updating below-

param ([string] $SourceFolder, [string] $DestFolder,  [string] $DDate);
if ($SourceFolder -eq "" -or $DestFolder -eq "" -or $DDate -eq "")
{ 
write-host "
`t You failed to specify correct syntax
`n
`t Usage: script.ps1 -sourcefolder c:\folder -destfolder c:\folder2 -ddate 40 
" -fore red
}
else
{
if (!(Test-Path $SourceFolder)) 
{ write-host "Source $sourcefolder does not exist!" }
if (!(Test-Path $DestFolder)) 
{ write-host  "Destination $destfolder does not exist!" }

$FileList = Get-ChildItem $SourceFolder -recurse
ForEach ($FileObj in $FileList) {
if ($fileobj.LastWriteTime -lt (Get-Date).AddDays(-$Ddate))
	{
$FileName = $FileObj.Name
$fullpath = $FileObj.FullName
$copypath = ($fullpath -replace [regex]::Escape($SourceFolder), '')
$destpath = $DestFolder + $copypath

Copy-Item $fullpath $destpath
	}
				}
}

Open in new window


Give it a go ...
If you need any extra functionality like not copying files already present etc let me know.
0
 
LVL 29

Expert Comment

by:becraig
ID: 38740585
Were you able to test this and did you have any additional questions ?
0
 

Author Comment

by:DTS-Tech
ID: 38742328
Sorry for the delay in the update, I haven't moved the files yet, but at this stage I think I'll end up using the Richcopy application due to the GUI. Though I do appreciate the script you've written out
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question