Auto-Repair Tool

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

Move files and folders older than x days If your download folder is filled with files, you can automatically move files 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:

Alternative Solutions: Auto-Repair Your PC And Drivers

Still Having Trouble? Try TWEAKBIT FIXMYPC - FREE

Published: Thursday, April 9th, 2015 Last Modified: April 9, 2015

Related Posts

Rate This Article
5 of 5 0 (100%) 1 vote