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
2023-06-22 02:27:27 +01:00

41 lines
1.3 KiB
PowerShell

$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 folder the video was in if it is empty, and is not the source folder
$folder = Split-Path $file.FullName -Parent
if ($folder -ne $from -and (Get-ChildItem -Path $folder -File).Count -eq 0) {
Remove-Item -Path $folder -Force
Write-Host "Removed $folder"
}
}