Solved

Script Help - Moving old files

Posted on 2013-05-21
5
136 Views
Last Modified: 2014-09-27
Hi,

I'm wondering if someone could help me. I'm looking for assistance in script creation.

At the moment I have a drive full of files. What I'm going to do is create an archive drive.

What I would like to do is move all the files that were last accessed over 4 years ago to this new drive but maintain the directory structure. So they are moved to the same directory but in a new location.

I can locate the files using this script

get-childitem G:\ -Exclude CaseTracking,Sage50 -rec -ErrorAction SilentlyContinue | where {!$_.PSIsContainer -AND $_.lastAccessTime -lt (Get-Date).AddDays(-1460)} | select-object FullName, LastWriteTime | export-csv -notypeinformation -delimiter '|' -path c:\temp\file.csv

Open in new window


Just wondering if someone could help me modifying the script to help me achieve what I am after?


Thanks
0
Comment
Question by:Phil Pearce
[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
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39184044
change $sourceDir and $archiveDir before running the script.
cls
$archiveDir = "c:\delete_archive\"
$sourceDir = "g:\"
$files = get-childitem $sourceDir -Exclude CaseTracking,Sage50 -rec -ErrorAction SilentlyContinue | where {!$_.PSIsContainer -AND $_.lastAccessTime -lt (Get-Date).AddDays(-10)} | select-object FullName, LastWriteTime

$files | %{
	$file = $_.FullName.ToLower()
	$archive = $file.Replace($sourceDir.ToLower() , $archiveDir.ToLower())
	New-Item -ItemType directory -Path ([System.IO.Path]::GetDirectoryName($archive)) -ErrorAction SilentlyContinue
	Copy-Item $file -Destination $archive -Force 
}

Open in new window

0
 
LVL 40

Accepted Solution

by:
footech earned 250 total points
ID: 39185397
Not a scripting solution, but if you're interested have you tried robocopy with the /maxlad switch?  You should be able to just run something like
robocopy g:\sourcedir d:\destinatindir /E /XD CaseTracking Sage50 /MAXLAD:1460 /R:2 /W:1

Open in new window

0
 
LVL 54

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points
ID: 39185432
And of course, if you do indeed want to move, not just copy, as I think you indiocated, use the /MOVE or /MOV option with ROBOCOPY.

~bp
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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