Jump to content

Recommended Posts

Posted

Hi,

 

We are looking to go through our shared drives and remove anything that hasnt been accessed in a few years.

 

We would like to be able to search for files that havnt been accessed and then move them to our archive area. We would however like to keep the file in the same directory. e.g. if a file came out of english\ks4 it moves archive\english\ks4.

 

Is there a bit of software to do this?

 

Many thanks,

 

Dan

Posted

You can do it pretty easily with any scripting language, heres an example in powershell. I didn't test it that much :p

 

function New-ArchiveFolder()
{
param($SourceFolder, $DestFolder)

$folder = New-Object PSObject
$folder | Add-Member -Type NoteProperty -Name Source -Value $SourceFolder
$folder | Add-Member -Type NoteProperty -Name Destination -Value $destFolder
return $folder
}

# Array of archive folders to process for archving
$archiveFolders = @(
(New-ArchiveFolder -SourceFolder "C:\Intel" -DestFolder "C:\Archive\Intel")
)
# Minimum age in days of files to be archived
$minArchiveAge = 30

foreach ($archiveFolder in $archiveFolders)
{
if (!(Test-Path $archiveFolder.Source)) { continue }

$sourceFolderUri = New-Object System.Uri("$($archiveFolder.Source)\")

$files = (Get-ChildItem -Path $archiveFolder.Source -Recurse | where { !$_.PsIsContainer -and (((Get-Date) - $_.LastAccessTime).Days -ge $minArchiveAge) })

if (!$files) { continue }

foreach ($file in $files)
{
	$fileName = $file.Name
	$filePath = $file.DirectoryName
	$filePathUri = New-Object System.Uri("$filePath\")
	$archivePathUri = $sourceFolderUri.MakeRelativeUri($filePathUri)
	$archivePath = "$($archiveFolder.Destination)\$($archivePathUri.ToString())"
	
	if (!(Test-Path $archivePath))
	{
		New-Item $archivePath -Type Directory
	}
	
	$file.MoveTo("$archivePath\$fileName")
}
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...