Powershell: Moving files from sub-folders to single folder

Jan 21, 2016 | | Say something

So I had a folder with about 100 sub-folders and within these sub-folders were “.cab” files. Every month I would go through each sub-folder manually and move the .cab files to a single folder. And you will agree with me when I say this is time consuming and also a strenuous little exercise.

So I thought it would be much easier if I can automate this task with Powershell. So I came up with this little Powershell script that would search through all my sub-folders and move all the .cab files it could find into a single folder.

—Powershell Script Start—

<#
.SYNOPSIS
Loop through folder and sub-folders
.DESCRIPTION
Loop through the folder / sub-folders and move all the *.cab files to single directory
.PARAMETER NotSpecified
No parameters in this script
.EXAMPLE
No example in this script
.Author Anton Potgieter
.Date 20 January 2016
#>

$OldLocation = ‘C:\Temp’
$NewLocation = ‘D:\Temp\Extracted’
$FileType = ‘*.cab’

get-childitem $OldLocation -rec -include $FileType | move-item -destination $NewLocation

—Powershell Script End—

The script saved me more than 2 hours work, which was great, so now I use it to make my life a little easier.

2,439 total views, 4 views today

Posted in: Powershell | Tags: , , ,

Leave a Reply