moving files to a new directory and deleting remaining files

by bryanleesterk at 2013-01-06 17:34:03

I am a complete noob to this which I’m sure will be obvious by my question but here it goes. I’m trying to come up with a script to search my directory "c:\Users\bryan\Downloads" for any files larger than 100mb & move them to c:\Users\bryan\Movies. all of the files in the original path are in sub folders and i would like to delete all of the original folders and files smaller than 100mb after the move is complete. I’ve tried patching together some scripts i found online but not working. If anyone could point me in the right direction I would appreciate it.
by nohandle at 2013-01-07 02:59:31
[quote="bryanleesterk"] I’m trying to come up with a script to search my directory "c:\Users\bryan\Downloads" for any files larger than 100mb & move them to c:\Users\bryan\Movies. all of the files in the original path are in sub fold[/quote]
Do you need to preserve the folder structure also in the movies folder? like… Downloads\something\film.avi becomes Movies\something\film.avi. Or you don’t care?
Checking for file extension seems like better idea to find movies than checking for filesize.

Without preserving the structure you do simply this:
$sourcePath = 'C:\temp\mhdd'
$destinationPath = 'c:\Temp'
#clear error list
$Error.Clear()
#folders have length (size) empty -> they are filtered out automatically
Get-ChildItem -Recurse -Path $sourcePath |
Where-Object {$_.length -ge 100MB} |
Move-Item -Destination $destinationPath -Force
#no errors in the previous commands, I can delete
#the count is 0 -> false, -not false is true
if (-not $error.Count)
{
#* because you want to delete just the contents of the folder not the folder itself
Remove-Item "$sourcePath*" -Force -Recurse -Confirm
}
else
{
Write-Warning 'No items deleted, there were errors in the previous commands.'
}
by bryanleesterk at 2013-01-07 07:34:27
I do not need to keep the folder structure. I thought about using the extension instead of size but since there are multiple extensions for video files, I thought size may be a better way to go. Thanks for the reply! I will give it a shot and let you know how it works.
by bryanleesterk at 2013-01-07 11:34:53
Thank you so much this works perfectly for what i asked for. Just a couple things if you don’t mind. #1 After the files have been moved i get a confirmation dialog asking if i want to delete the original folders. Is there anyway to bypass this and just delete them automatically? #2 Is there any way that PS can display the task that it is doing? #3 would you be able to give me an example of the script if i wanted to filter say .avi and .mp4 extensions instead of by size. Thank you so much in advance. hopefully someday soon I will have the time and resources to learn this on my own and pass it on to others like you have done for me.
by nohandle at 2013-01-07 13:34:25
1) yes there is, just ommit the confirm paramter on the remove-item function
2) try adding -verbose to the commands you need more info from to see if the info level is sufficient.
3) you ommit the where part, and use -include ‘.avi’,'.mp4’ after the get-child item command.
posting from mobilephone so i cannost show you exactly how to do it now.
by bryanleesterk at 2013-01-09 18:23:45
Just wanted to let you know it works perfect! I actually combined the two script and added a few lines (ones i could figure out on my own). I know have a scheduled task that shuts uTorrent down, moves the files i want based on the extension to a hidden folder, and deletes the ones i don’t don’t want finished downloads directory. It then deletes samples (if there are any) based on the size script, and moves the file i want to it’s final directory, where Media Center Master downloads the correct metadata and cover art, renames the file and creates a directory that matches the file name. And then relaunches uTorrent. Thank you so much for your help!!! This truly opens up a world of computing that most people have no idea even exists.
by nohandle at 2013-01-10 00:56:57
Hope you download only legal content. :slight_smile: