Powershell: Move files and folders older than X days to new location


If your download folder is filled with files, you can automatically move files older than X days.

Move files and folders older than x days

The Script

The scripts is short and simple:

$age = 10 # define days here
[IO.Directory]::CreateDirectory(“$env:USERPROFILE\Pictures\Archive1″)

get-childitem -Path “$env:USERPROFILE\Pictures\” | where { ! $_.PSIsContainer } | where-object {$_.LastWriteTime -lt (get-date).AddDays(-$days)} | move-Item -force -Destination “$env:USERPROFILE\Pictures\Archive1\”

Basically, we’re gtting a list of the folder using get-childitem, then we check if its a file or folder, then we check if the object is older than x days using a where-object check and finally move it to a new destination using the -force command to overwrite files.

Tips: How to modify this script for own purposes

TIP: If you want to move folders as well, then remove where { ! $_.PSIsContainer } |

TIP2: Before you run the script on an actual folder, run a few tests. Replace Downloads with one of the library folders e.g. Videos, Documents to create additional moving scripts that move files in other foles.

TIP3: If you want to run the script via Powershell read this:

TIP4: You can schedule Powershell scripts using the built-in Windows task scheduler

Move Files Older Than X Days in Downloads Folder

This script moves all files and folders in the Downloads folder:

Move Files Older Than X Days in Music Folder

This script moves all files and folders in the Music folder:

Move Files Older Than X Days in Pictures Folder

This script moves all files and folders in the Pictures folder:


Or you might like these sexy wallpaper, tweaks and themes:

Written by oliversk Wednesday, December 21st, 2011

Was it helpful? Please bookmark it and spread the word

delicious   facebook   google   twitter  

You love Windows, Gaming and everything digital? Great, we too! We have thousands of great Windows 7 themes, registry tweaks, tutorials, so please use our search box if you look for anything specific. If you have some awesome desktop themes, tips or want to write for us, then drop us a mail: win7themes at googlemail.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>