Subfolders fore each video file found in a main folder and then move that file into the folder with the same name without the extension in it
Code: Select all
# movie_folders.ps1 v1.0 by kristoffe.brodeur. ©2024 All rights reserved.
# 12/16/2024
# Get the folder where the script is located
$folderPathCurrent = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
Write-Host "Script is running in folder: $folderPathCurrent"
# Get all .avi, .flv, .mp4, or .mkv files in the current directory (and subdirectories)
$files = Get-ChildItem -Path "$folderPathCurrent\*" -Recurse -Include *.avi, *.flv, *.mp4, *.mkv -File -Force
Write-Host "Found $($files.Count) video files."
foreach ($file in $files) {
Write-Host "Processing file: $($file.FullName)"
# Get the file name without the extension
$folderName = [System.IO.Path]::GetFileNameWithoutExtension($file.FullName)
Write-Host "Target folder name: $folderName"
# Create the target folder path
$targetFolder = Join-Path -Path $folderPathCurrent -ChildPath $folderName
Write-Host "Target folder path: $targetFolder"
# Check if the folder already exists, if not, create it
if (-not (Test-Path -Path $targetFolder)) {
Write-Host "Creating folder: $targetFolder"
New-Item -ItemType Directory -Path $targetFolder | Out-Null
} else {
Write-Host "Folder already exists: $targetFolder"
}
# Move the file to the new folder
Write-Host "Moving file to folder: $targetFolder"
try {
Move-Item -Path $file.FullName -Destination $targetFolder -ErrorAction Stop
Write-Host "Successfully moved: $($file.FullName)"
} catch {
Write-Host "Error moving file: $($file.FullName). $_"
}
}
Write-Host "Operation completed successfully."
For Windows 11, Windows 10, Windows 7, Windows 8, Windows Server 2008 R2 or Windows Server 2012, run the following commands as Administrator:
x86 (32 bit)
Open C:\Windows\SysWOW64\cmd.exe
Run the command
Code: Select all
powershell Set-ExecutionPolicy RemoteSigned
Open C:\Windows\system32\cmd.exe
Run the command
Code: Select all
powershell Set-ExecutionPolicy RemoteSigned
In CMD: echo %PROCESSOR_ARCHITECTURE%
In Powershell: [Environment]::Is64BitProcess
https://stackoverflow.com/questions/403 ... his-system
by Ralph Willgoss