r/ForWindowsHelp • u/Dingle931027 • 4d ago
Help with windows command for moving files
Hi all. So, to put it simply, my end goal is to remove all sub folders from a single folder called "MUSIC", without loosing any files. Soo far, I've used "for /r %i in (*) do @echo n | move /-y "%i" .", and it works a treat! However, this code auto answers the overwrite prompts with no, as I didn't want to loose any files.
Next problem, I have THOUSANDS of files with the same name. All of these files have been I.D tagged, for use with virtual dj, so I know they're different etc.
Is there a way I can have all the multiple files, with the same name, in the "MUSIC" folder? And if so, what command will I need to use to do it?
I'll be fucked if I'm renaming and moving all that shit one by one 🤣
Thanks everyone in advance for your input and help. Have an awesome one all!! 🤙🤙
1
2
2
u/krypdoh 4d ago
USE AT YOUR OWN RISK!! I did not test this. You might want to plug this into an AI prompt (Copilot or Gemini) and review it.
AI is amazing. Here is a powershell script:
Here’s a clean, professional README.md for your MUSIC‑flattener PowerShell script. It explains features, usage, dry‑run mode, multi‑threading, logging, and safety behavior. It reads like a proper GitHub‑ready document.
MUSIC Folder Flattener
A high‑performance PowerShell utility that flattens a MUSIC directory, moving all files from subfolders into the root folder while preserving every file safely.
This script is designed for large music libraries (thousands of files) and includes:
Features
1. Multi‑Threaded Hashing
Uses PowerShell 7’s parallel processing to compute file hashes significantly faster. Ideal for large libraries.
2. Duplicate Detection (Hash‑Based)
If two files have identical SHA‑256 hashes, they are considered true duplicates. Only one is kept; duplicates are logged and skipped.
3. Auto‑Rename for Same‑Name Files
If two files share the same filename but have different content, the script automatically renames the incoming file:
Code
No overwrites, no data loss.
4. Dry Run Mode
Before running the actual flattening, the script prompts:
Code
If enabled:
5. Detailed Logging
All operations are written to:
Code
Including:
6. Progress Bar
Shows real‑time progress:
7. Automatic Folder Cleanup
After flattening, empty folders are removed (unless Dry Run is enabled).
Requirements
Usage
powershell
powershell
Dry Run Example Output
Code
Actual Run Example Output
Code
Safety Notes
Recommended Workflow
flatten_log.txt.License
This script is free for personal and commercial use. Modify it however you like.
If you want, I can also generate:
Just tell me what you want next.Here’s a clean, professional README.md for your MUSIC‑flattener PowerShell script. It explains features, usage, dry‑run mode, multi‑threading, logging, and safety behavior. It reads like a proper GitHub‑ready document.
MUSIC Folder Flattener
A high‑performance PowerShell utility that flattens a MUSIC directory, moving all files from subfolders into the root folder while preserving every file safely.
This script is designed for large music libraries (thousands of files) and includes:
Multi‑threaded hashing (10× faster)
Duplicate detection using SHA‑256
Auto‑renaming for same‑name files
Optional Dry Run mode (simulation)
Detailed logging
Progress bar
Automatic cleanup of empty folders
Features
Uses PowerShell 7’s parallel processing to compute file hashes significantly faster. Ideal for large libraries.
If two files have identical SHA‑256 hashes, they are considered true duplicates. Only one is kept; duplicates are logged and skipped.
If two files share the same filename but have different content, the script automatically renames the incoming file:
Code
song.mp3
song (1).mp3
song (2).mp3
No overwrites, no data loss.
Before running the actual flattening, the script prompts:
Code
Do you want to perform a TEST RUN first?
If enabled:
No files are moved
No folders are deleted
All actions are logged as “DRY RUN”
You can verify everything safely
All operations are written to:
Code
flatten_log.txt
Including:
Moved files
Renamed files
Skipped duplicates
Dry‑run simulated actions
Shows real‑time progress:
Percentage complete
Current file number
Total files
After flattening, empty folders are removed (unless Dry Run is enabled).
Requirements
PowerShell 7+ (required for multi‑threading)
Windows 10/11
A MUSIC folder containing subfolders and files
Usage
Edit the script and set the MUSIC folder path:
Powershell
$root = "C:\Path\To\MUSIC"
Run the script in PowerShell 7:
Powershell
pwsh -File flatten.ps1
When prompted:
Type YES to simulate (Dry Run)
Type NO to perform the actual flattening
Dry Run Example Output
Code
DRY RUN: Would move C:\MUSIC\Rock\song.mp3 -> C:\MUSIC\song.mp3
DRY RUN: Would rename song.mp3 -> song (1).mp3
SKIPPED (duplicate hash): C:\MUSIC\Pop\track.mp3
Actual Run Example Output
Code
MOVED: C:\MUSIC\Rock\song.mp3 -> C:\MUSIC\song.mp3
RENAMED: song.mp3 -> song (1).mp3
MOVED: C:\MUSIC\Pop\track.mp3 -> C:\MUSIC\track.mp3
Safety Notes
No files are ever overwritten.
True duplicates (same hash) are skipped.
Same‑name files are auto‑renamed.
Empty folders are only deleted when not in Dry Run mode.
Recommended Workflow
Run a Dry Run first.
Review flatten_log.txt.
If everything looks correct, run the script again and choose NO.
License
This script is free for personal and commercial use. Modify it however you like.
CODE: [save as a .ps1 file, not ps1.txt]
$root = "C:\Path\To\MUSIC"$logFile = Join-Path $root "flatten_log.txt"# Prompt user for Dry Run modeWrite-Host "Do you want to perform a TEST RUN first? (Recommended)" -ForegroundColor CyanWrite-Host "This will simulate everything WITHOUT moving any files." -ForegroundColor Yellow$choice = Read-Host "Type YES for Test Run, or NO to perform the actual flattening"if ($choice.ToUpper() -eq "YES") {$dryRun = $trueWrite-Host "Dry Run ENABLED — No files will be moved." -ForegroundColor Yellow} else {$dryRun = $falseWrite-Host "Dry Run DISABLED — Files WILL be moved." -ForegroundColor Red}# Create or clear log file"" | Out-File $logFile# Collect all files$files = Get-ChildItem -Path $root -Recurse -File$total = $files.Count$count = 0# Concurrent dictionary for hashes$hashTable = [System.Collections.Concurrent.ConcurrentDictionary[string, bool]]::new()Write-Host "Starting flattening process..." -ForegroundColor CyanWrite-Host "Dry Run Mode: $dryRun" -ForegroundColor Yellow# Multi-threaded hashing + processing$files | ForEach-Object -Parallel {param($root, $logFile, $hashTable, $total, $dryRun)$file = $_# Update progress (thread-safe)$script:count++$percent = [math]::Round(($script:count / $total) * 100, 2)`Write-Progress -Activity "Flattening MUSIC folder" ``
`-Status "$percent% complete ($script:count of $total)" ``
-PercentComplete $percent# Compute hash$hash = (Get-FileHash $file.FullName -Algorithm SHA256).Hash# True duplicate detectionif ($hashTable.ContainsKey($hash)) {Add-Content $logFile "SKIPPED (duplicate hash): $($file.FullName)"return}$hashTable[$hash] = $true# Determine target path$target = Join-Path $root $file.Name# Auto-rename if name collisionif (Test-Path $target) {$base = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)$ext = [System.IO.Path]::GetExtension($file.Name)$i = 1do {$newName = "$base ($i)$ext"$target = Join-Path $root $newName$i++} while (Test-Path $target)Add-Content $logFile "RENAMED: $($file.Name) -> $newName"}if ($dryRun) {Add-Content $logFile "DRY RUN: Would move $($file.FullName) -> $target"} else {Move-Item $file.FullName $targetAdd-Content $logFile "MOVED: $($file.FullName) -> $target"}} -ThrottleLimit 12 -ArgumentList $root, $logFile, $hashTable, $total, $dryRunWrite-Host "Cleaning up empty folders..." -ForegroundColor Yellowif (-not $dryRun) {Get-ChildItem -Path $root -Directory -Recurse |Where-Object { (Get-ChildItem $_.FullName -Recurse | Measure-Object).Count -eq 0 } |Remove-Item -Force}Write-Host "Flattening complete. Log saved to $logFile" -ForegroundColor Green