mirror of
https://github.com/serialexperiments0815/PowershellExcercises.git
synced 2026-07-12 15:32:25 +00:00
25 lines
No EOL
1.1 KiB
PowerShell
25 lines
No EOL
1.1 KiB
PowerShell
# Assign all relevant file-extensions to arrays to easily filter through them during a for-loop
|
|
# This approach was choosen for its simplicity and visibility
|
|
|
|
[String[]]$videoFormat = "mp4", "mkv", "mov", "avi", "wmv", "flv", "webm", "mpeg", "mpg", "m4v", "3gp", "ogv", "ts", "vob"
|
|
[String[]]$pictureFormat = "jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "webp", "heic", "heif", "raw", "cr2", "nef", "arw", "svg", "ico"
|
|
[String[]]$documentFormat = "pdf", "doc", "docx", "odt", "rtf", "txt", "csv", "xls", "xlsx", "ods", "ppt", "pptx", "odp", "md", "html", "xml"
|
|
|
|
$filesInFolder = Get-ChildItem -Path "./" -File
|
|
|
|
foreach($file in $filesInFolder){
|
|
$extension = $file.Extension.TrimStart('.').ToLower()
|
|
|
|
if ($videoFormat -contains $extension){
|
|
Move-Item -Path $file.FullName -Destination "./videos/$($file.Name)"
|
|
}
|
|
|
|
elseif ($pictureFormat -contains $extension) {
|
|
Move-Item -Path $file.FullName -Destination "./pictures/$($file.Name)"
|
|
}
|
|
|
|
elseif ($documentFormat -contains $extension) {
|
|
Move-Item -Path $file.FullName -Destination "./documents/$($file.Name)"
|
|
}
|
|
|
|
} |