From 0b63a079c33e41f711eba4945848d0948491052f Mon Sep 17 00:00:00 2001 From: Fascinated Date: Thu, 22 Jun 2023 02:19:27 +0100 Subject: [PATCH] create inital mover --- mover.ps1 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 mover.ps1 diff --git a/mover.ps1 b/mover.ps1 new file mode 100644 index 0000000..5208fa2 --- /dev/null +++ b/mover.ps1 @@ -0,0 +1,40 @@ +$from = "$env:USERPROFILE\Videos" # Videos folder eg: C:\Users\username\Videos +$to = "Z:\Recordings" # Destination folder (Change this to the destination folder) + +# Check if the source folder exists +if (!(Test-Path $from)) { + Write-Host "Source folder $from does not exist" + exit +} + +# Check if the destination folder exists +if (!(Test-Path $to)) { + Write-Host "Destination folder $to does not exist" + exit +} + +# Get all files in the source folder +$files = Get-ChildItem -Path $from -File -Recurse + +# Log if there are no files in the source folder +if ($files.Count -eq 0) { + Write-Host "No files in the source folder $from" + exit +} + +# Move each file to the destination folder and create the folder if it doesn't exist +foreach ($file in $files) { + $dest = $file.FullName.Replace($from, $to) + $destFolder = Split-Path $dest -Parent + if (!(Test-Path $destFolder)) { + New-Item -Path $destFolder -ItemType Directory -Force + } + Move-Item -Path $file.FullName -Destination $dest -Force + Write-Host "Moved $file" + + # Remove the source folder if it is empty + if (!(Get-ChildItem -Path $from -File -Recurse)) { + Remove-Item -Path $from -Force + Write-Host "Removed the folder $from, it is empty" + } +} \ No newline at end of file