This repository has been archived on 2023-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
shadowplay-to-nas/mover.ps1

40 lines
1.2 KiB
PowerShell
Raw Normal View History

2023-06-22 01:19:27 +00:00
$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"
}
}