create inital mover
This commit is contained in:
parent
85bd30cab1
commit
0b63a079c3
40
mover.ps1
Normal file
40
mover.ps1
Normal file
@ -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"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user