Often, in your document folders a lot of files exist, and most of the time they are not really organized. With the help of a little PowerShell script, you can easily clean up and organize your files based on file type.
Warning: The following script will move file content into organized subfolders. Do this only on folders that contain documents. Never try and "clean up" the windows folder or a program folder or else programs will be damaged. Try at your own risk!
The script cleans up your documents folder. It will only clean up file types listed in the $types array. It creates a subfolder for each type listed in $types and then moves the files into that subfolder.
(Note: the folder $home\Documents exists on Vista and above only. On XP, adjust the path accordingly)
$folder = "$home\Documents"
$types = ".bmp", ".jpg", ".doc", ".ps1", ".ocx", ".pdf",
".docx", ".txt", ".vbs", ".xls", ".zip", ".htm", ".bat"
$files= dir $folder | Where-Object { -not $_.PSisContainer } |
Group-Object Extension
$files = $files | Where-Object { $types -contains $_.Name }
$files | ForEach-Object { New-Item -itemType Directory -path `
"$folder\$($_.Name)" -ea SilentlyContinue }
$files | ForEach-Object { $_.Group | Move-Item -destination `
"$folder$($_.Extension)\$($_.Name)" }
To clean up your downloads folder, simply change $folder to $folder = "$home\Downloads".
Posted
Feb 27 2009, 08:00 AM
by
ps1