diff --git a/.specstory/history/2025-12-19_18-52Z-texture-commonality-folder-structure.md b/.specstory/history/2025-12-19_18-52Z-texture-commonality-folder-structure.md index 12c3c55..c59731b 100644 --- a/.specstory/history/2025-12-19_18-52Z-texture-commonality-folder-structure.md +++ b/.specstory/history/2025-12-19_18-52Z-texture-commonality-folder-structure.md @@ -7371,7 +7371,7 @@ Additional data: "codeblockId": "4847ba4f-4666-4d56-9eb5-fc4ea2aaabab" } ``` -Status: **loading** +Status: **completed** @@ -7379,3 +7379,883 @@ Status: **loading** --- + +Removing duplicates folder creation and updating Pass 1 calls: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Updating Pass 1 to remove duplicates folder creation and update the call: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "a5a4e114-b913-4fd7-9267-0f8d5461f422" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updating the Pass 1 summary message: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "86dbaa71-f9dd-4877-92b9-a496350ac9cd" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updating Pass 2 similarly: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Updating Pass 2: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "7f1a3f6b-71df-42b5-b1c1-0e321a0a7fe0" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updated the script to delete duplicate files instead of moving them to a duplicates folder. Changes: + +1. **Removed `DuplicatesPath` parameter** from `Process-DuplicateGroup` function +2. **Changed duplicate handling** - duplicates are now deleted using `Remove-Item` instead of being moved to a duplicates folder +3. **Removed duplicates folder creation** - no longer creates `\common\duplicates` directories in Pass 1 or Pass 2 +4. **Updated all messages** - changed "moved to \common\duplicates" to "deleted" to reflect the new behavior + +The script now: +- Keeps one copy of each duplicate file in the common folder +- Deletes all other duplicates to save space +- No longer creates or uses duplicates subfolders + +When you run it, duplicate files will be deleted after the first copy is moved to the common folder, saving disk space. + +--- + +_**User**_ + +@pwsh (357-1075) ah, let's have it move all FlatColors to the inter-blendfile \common folder as well. + +--- + +_**Agent (model default, mode Agent)**_ + + +Updating Pass 2 to also move files containing "FlatColors" to the inter-blendfile `\common` folder, even if they're not duplicates: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Adding logic to move FlatColors files to the common folder after duplicate processing: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "cffef2ad-0b31-4a38-9241-1080d28c6a86" +} +``` +Status: **completed** + + +
+
+ +--- + + +Fixing the variable name case: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Fixing the variable name to match: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "af40fe44-3e54-44ce-8f07-a694e52051f0" +} +``` +Status: **completed** + + +
+
+ +--- + + +Adding a check to ensure the file still exists before moving it (in case it was already moved during duplicate processing): + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "cc15b99a-e2d7-4f52-8186-be98b4fb2162" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updated Pass 2 to also move all files containing "FlatColors" in their name to the inter-blendfile `\common` folder, even if they're unique (not duplicates). The changes: + +1. **Added FlatColors processing** - After processing duplicate groups, the script now finds all files with "FlatColors" in their name +2. **Strips blendfile prefixes** - FlatColors files also have their blendfile prefixes stripped (e.g., "Demarco_FlatColors.jpg" → "FlatColors.jpg") +3. **Handles name conflicts** - If multiple FlatColors files would have the same name after prefix stripping, they get numbered suffixes +4. **Checks file existence** - Only processes FlatColors files that still exist at their original location (in case they were already moved during duplicate processing) + +When you run the script, all FlatColors files will be moved to `\textures\common` along with the duplicate files, with blendfile prefixes stripped. + +--- + +_**User**_ + +@pwsh (995-1075) it didn't add a `\\textures\common\FlatColors` folder and it didn't move any of the FlatColors there. + +--- + +_**Agent (model default, mode Agent)**_ + + +Updating the code to create a `\textures\common\FlatColors` subfolder and move FlatColors files there: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Updating the code to create a `\textures\common\FlatColors` subfolder and move FlatColors files there: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "ccca3757-4691-405a-8e37-53dd61be3fbb" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updated the code to: + +1. **Create `\textures\common\FlatColors` subfolder** - Creates the directory if it doesn't exist +2. **Use separate tracking** - Uses `$filesInFlatColors` hashtable to track files in the FlatColors folder (separate from the root common folder) +3. **Update destination paths** - All FlatColors files are moved to `\textures\common\FlatColors` instead of directly to `\textures\common` +4. **Update messages** - Messages now reflect the correct destination + +When you run the script, it will: +- Create the `\textures\common\FlatColors` folder if it doesn't exist +- Move all files containing "FlatColors" in their name to that subfolder +- Strip blendfile prefixes from FlatColors filenames +- Handle name conflicts within the FlatColors folder + +The FlatColors files will be organized in their own subfolder within the common directory. + +--- + +_**User**_ + +@pwsh (356-1075) i still see no FlatColors folder in \\textures\common + +--- + +_**Agent (model default, mode Agent)**_ + + +Checking why FlatColors files aren't being found. The filter may be running after they're already moved, or the pattern isn't matching. Reviewing the code and adding debug output: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +The issue is that we're checking `$filesWithChecksums` after duplicates are processed, so files may have already been moved. We should check the original `$remainingFiles` list instead. Updating the code: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "b1e0cbb6-fa2a-4be0-b29b-59895d935281" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updating the loop to work with FileInfo objects directly: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Updating the loop to use FileInfo objects directly: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "c06058ea-80c8-4195-a6d5-c077447a6411" +} +``` +Status: **completed** + + +
+
+ +--- + + +Fixed the issue. The code was checking `$filesWithChecksums` (custom objects with a `.File` property) after duplicates were processed, so some files may have already been moved. Changes: + +1. **Check `$remainingFiles` directly** - This is the original file list before any processing, so it includes all FlatColors files that haven't been moved yet +2. **Use FileInfo objects directly** - Since `$remainingFiles` contains FileInfo objects, we use `$file` directly instead of `$fileObj.File` + +The script will now: +- Find all FlatColors files from the original remaining files list +- Create the `\textures\common\FlatColors` folder +- Move all FlatColors files there, stripping blendfile prefixes as needed + +When you run the script, it should create the FlatColors folder and move the files there. + +--- + +_**User**_ + +@pwsh (1-698) still no FlatColors relocation. + +--- + +_**Agent (model default, mode Agent)**_ + + +Adding debug output to see why FlatColors files aren't being found. Checking if they're being excluded or already moved: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +FlatColors files may have already been moved during duplicate processing. Checking for them before duplicate processing and handling them separately. Updating the code: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Restructuring to handle FlatColors files before duplicate processing and exclude them from the duplicate loop: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "79972c53-e0e2-4130-a3c9-a43564ffd3f1" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updating the FlatColors processing to use the pre-filtered list: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Adding debug output to see if FlatColors files are being found: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "c620ec8a-a87c-4377-90ed-577acc15dceb" +} +``` +Status: **completed** + + +
+
+ +--- + + +Adding an else clause to show when no FlatColors files are found: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "90044f8c-d9a6-4a70-ba89-21085a56910c" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updated the script to: + +1. **Identify FlatColors files first** - Separates them from other files before duplicate processing +2. **Exclude from duplicate processing** - FlatColors files are filtered out of the checksum grouping so they aren't processed as duplicates +3. **Add debug output** - Shows how many FlatColors files were found +4. **Handle separately** - Moves all FlatColors files to `\common\FlatColors` regardless of whether they're duplicates + +The script will now: +- Find all FlatColors files before any duplicate processing +- Process duplicates for non-FlatColors files +- Then move all FlatColors files to `\textures\common\FlatColors` with prefixes stripped + +When you run it, you should see messages indicating how many FlatColors files were found and moved. + +--- + +_**User**_ + +@pwsh (353-1075) how did it find no FlatColors? + +--- + +_**Agent (model default, mode Agent)**_ + + +The script matches filenames containing "FlatColors", but these files are in a `FlatColors` folder and named with hex codes (e.g., `#000000.png`). Updating the search to include files in a `FlatColors` folder path: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +FlatColors files are in `[blendfile]\common\FlatColors`, so they're excluded by the `$remainingFiles` filter that excludes `*\common\*`. Collecting FlatColors files separately, including those in common folders: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Updating the code to collect FlatColors files from anywhere, including those in `\common\FlatColors` folders: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "fea6d4a8-6d9b-40ce-8281-2f5aac7bc93e" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updating the debug output to show how many FlatColors files were found: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "60bb9a02-854d-418b-a45a-b91013a7944a" +} +``` +Status: **completed** + + +
+
+ +--- + + +Excluding files already in the root `\textures\common\FlatColors` folder: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "b7cacb81-a662-40f7-9058-7cafe450291e" +} +``` +Status: **completed** + + +
+
+ +--- + + +The script now: + +1. **Collects FlatColors files separately** - Searches for files in any `\FlatColors\` folder or with "FlatColors" in their name +2. **Excludes files already in the target** - Skips files already in `\textures\common\FlatColors` to avoid moving files that are already in place +3. **Includes files from blendfile common folders** - Finds FlatColors files in `[blendfile]\common\FlatColors` folders that were excluded from `$remainingFiles` + +When you run the script, it should find FlatColors files in folders like `Chan\common\FlatColors` and move them to `\textures\common\FlatColors`. The debug output will show how many FlatColors files were found. + +--- + +_**User**_ + +@pwsh (350-1075) Good. Duplicate FlatColors should be merged, too, no _1 or _2 suffixes. + +--- + +_**Agent (model default, mode Agent)**_ + + +Updating FlatColors processing to merge duplicates by checksum (keep one, delete the rest) instead of renaming with suffixes. Checking the current implementation: + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + + + + +--- + + +
Tool use: **read_file_v2** • Read file: a:\1 Amazon_Active_Projects\3 ProjectStructure\organize_textures.ps1 + +
+
+ +--- + + +Updating FlatColors processing to calculate checksums, group duplicates, and merge them (keep one, delete the rest) before moving: + + +--- + + +
+Tool use: **edit_file_v2** + + +Parameters: + +```json +{ + "relativeWorkspacePath": "a:\\1 Amazon_Active_Projects\\3 ProjectStructure\\organize_textures.ps1" +} +``` +Additional data: + +```json +{ + "codeblockId": "385c5b5b-de3b-4166-b1ca-4cde1fe2e62b" +} +``` +Status: **completed** + + +
+
+ +--- + + +Updated FlatColors processing to: + +1. **Calculate checksums** for all FlatColors files +2. **Group by checksum** to identify duplicates +3. **Merge duplicates**: For groups with multiple files, use `Process-DuplicateGroup` to keep one and delete the rest +4. **Move unique files**: Single-file groups are moved to `\common\FlatColors` + +This removes the `_1`, `_2` suffixes and merges duplicate FlatColors files, keeping one copy per unique checksum and deleting the rest. The script will report how many unique files were moved and how many duplicates were deleted. + +--- + +_**User**_ + +There should also be a small operation to purge empty folders at the end. + +--- + diff --git a/organize_textures.ps1 b/organize_textures.ps1 index b7550fc..461bd0f 100644 --- a/organize_textures.ps1 +++ b/organize_textures.ps1 @@ -336,7 +336,15 @@ if ($null -ne $blendfileFoldersForPrefixes) { Write-Host "Valid blendfile prefixes: $($validBlendfilePrefixes -join ', ')" -ForegroundColor Gray } -# Get all remaining files (excluding all \common folders) +# Collect FlatColors files separately (including those in \common\FlatColors folders, but not from root \common\FlatColors) +Write-Host "Collecting FlatColors files..." -ForegroundColor Yellow +$rootCommonFlatColorsPath = Join-Path -Path $textureFolderPath -ChildPath "common\FlatColors" +$allFlatColorsFiles = Get-ChildItem -Path $textureFolderPath -Recurse -File | Where-Object { + ($_.FullName -like "*\FlatColors\*" -or $_.Name -like "*FlatColors*") -and + $_.FullName -notlike "$([regex]::Escape($rootCommonFlatColorsPath))\*" +} + +# Get all remaining files (excluding all \common folders, but we'll handle FlatColors separately) Write-Host "Collecting remaining files..." -ForegroundColor Yellow $remainingFiles = Get-ChildItem -Path $textureFolderPath -Recurse -File | Where-Object { $_.FullName -notlike "*\common\*" } @@ -351,9 +359,17 @@ if ($null -eq $remainingFiles -or $remainingFiles.Count -eq 0) { Write-Host "Checksum calculation complete." -ForegroundColor Green - # Group files by checksum + # Separate FlatColors files from other files before processing + Write-Host "Identifying FlatColors files..." -ForegroundColor Yellow + $flatColorsFiles = $allFlatColorsFiles | Where-Object { (Test-Path -Path $_.FullName) } + $nonFlatColorsFiles = $remainingFiles | Where-Object { $_.Name -notlike "*FlatColors*" } + + Write-Host "Found $($flatColorsFiles.Count) FlatColors file(s) (including from \common\FlatColors folders), $($nonFlatColorsFiles.Count) other file(s)" -ForegroundColor Gray + + # Group non-FlatColors files by checksum Write-Host "Grouping files by checksum..." -ForegroundColor Yellow - $groupedByChecksum = $filesWithChecksums | Group-Object -Property Hash + $nonFlatColorsWithChecksums = $filesWithChecksums | Where-Object { $_.File.Name -notlike "*FlatColors*" } + $groupedByChecksum = $nonFlatColorsWithChecksums | Group-Object -Property Hash Write-Host "Found $($groupedByChecksum.Count) unique checksums." -ForegroundColor Green @@ -368,7 +384,7 @@ if ($null -eq $remainingFiles -or $remainingFiles.Count -eq 0) { # Track filenames already in \textures\common $filesInRootCommon = @{} - # Process each checksum group + # Process each checksum group (excluding FlatColors) Write-Host "Moving files to \common and deleting duplicates..." -ForegroundColor Yellow $pass2Moved = 0 $pass2Duplicates = 0 @@ -388,9 +404,132 @@ if ($null -eq $remainingFiles -or $remainingFiles.Count -eq 0) { $pass2Duplicates += $result.DuplicateCount } + # Process FlatColors files: merge duplicates and move to \common\FlatColors + Write-Host "Processing FlatColors files (merging duplicates)..." -ForegroundColor Yellow + + if ($null -ne $flatColorsFiles -and $flatColorsFiles.Count -gt 0) { + Write-Host "Found $($flatColorsFiles.Count) FlatColors file(s) to process" -ForegroundColor Gray + + # Calculate checksums for FlatColors files + Write-Host "Calculating checksums for FlatColors files..." -ForegroundColor Yellow + $flatColorsWithChecksums = Get-FilesWithChecksums -Files $flatColorsFiles + + # Group by checksum to find duplicates + $flatColorsGroupedByChecksum = $flatColorsWithChecksums | Group-Object -Property Hash + + Write-Host "Found $($flatColorsGroupedByChecksum.Count) unique FlatColors file(s)" -ForegroundColor Gray + + # Create \textures\common\FlatColors directory + $flatColorsPath = Join-Path -Path $rootCommonPath -ChildPath "FlatColors" + if (-not (Test-Path -Path $flatColorsPath -PathType Container)) { + New-Item -ItemType Directory -Path $flatColorsPath | Out-Null + Write-Host "Created directory: $flatColorsPath" -ForegroundColor Green + } + + # Track filenames already in \common\FlatColors + $filesInFlatColors = @{} + $flatColorsMoved = 0 + $flatColorsDuplicates = 0 + + foreach ($group in $flatColorsGroupedByChecksum) { + $files = $group.Group + + if ($files.Count -eq 1) { + # Single file - move to FlatColors folder + $fileObj = $files[0].File + $fileName = $fileObj.Name + + # Strip blendfile prefix if present + $strippedName = Get-FileNameWithoutPrefix -FileName $fileName -ValidPrefixes $validBlendfilePrefixes + if ($strippedName -ne $fileName) { + $fileName = $strippedName + } + + $destinationPath = Join-Path -Path $flatColorsPath -ChildPath $fileName + + # Handle name conflicts (shouldn't happen for unique files, but just in case) + if ($filesInFlatColors.ContainsKey($fileName) -or (Test-Path -Path $destinationPath)) { + $baseName = [System.IO.Path]::GetFileNameWithoutExtension($fileName) + $extension = [System.IO.Path]::GetExtension($fileName) + $counter = 1 + do { + $newFileName = "${baseName}_${counter}${extension}" + $destinationPath = Join-Path -Path $flatColorsPath -ChildPath $newFileName + $counter++ + } while ($filesInFlatColors.ContainsKey($newFileName) -or (Test-Path -Path $destinationPath)) + $fileName = $newFileName + } + + try { + Move-Item -Path $fileObj.FullName -Destination $destinationPath -Force + $filesInFlatColors[$fileName] = $true + $flatColorsMoved++ + } catch { + Write-Warning "Failed to move FlatColors file: $($fileObj.FullName) - $($_.Exception.Message)" + } + } else { + # Multiple files with same checksum (duplicates) - merge them + # Use Process-DuplicateGroup to handle merging + $result = Process-DuplicateGroup -Files $files -CommonPath $flatColorsPath -FilesInCommon $filesInFlatColors -StripPrefix -ValidPrefixes $validBlendfilePrefixes + $flatColorsMoved += $result.MovedCount + $flatColorsDuplicates += $result.DuplicateCount + } + } + + Write-Host "Moved $flatColorsMoved unique FlatColors file(s) to \common\FlatColors, deleted $flatColorsDuplicates duplicate(s)" -ForegroundColor Green + } else { + Write-Host "No FlatColors files found to process." -ForegroundColor Gray + } + Write-Host "" Write-Host "Pass 2 complete: $pass2Moved file(s) moved to \common, $pass2Duplicates duplicate(s) deleted" -ForegroundColor Green } +# Function to remove empty folders recursively +function Remove-EmptyFolders { + param( + [string]$Path, + [string]$RootPath + ) + + $removedCount = 0 + + # Get all subdirectories + $subdirs = Get-ChildItem -Path $Path -Directory -ErrorAction SilentlyContinue + + if ($null -ne $subdirs) { + foreach ($subdir in $subdirs) { + # Recursively process subdirectories first + $removedCount += Remove-EmptyFolders -Path $subdir.FullName -RootPath $RootPath + + # Check if this directory is now empty (after processing subdirectories) + $items = Get-ChildItem -Path $subdir.FullName -ErrorAction SilentlyContinue + if ($null -eq $items -or $items.Count -eq 0) { + # Don't remove the root path + if ($subdir.FullName -ne $RootPath) { + try { + Remove-Item -Path $subdir.FullName -Force -ErrorAction Stop + $removedCount++ + } catch { + Write-Warning "Failed to remove empty folder: $($subdir.FullName) - $($_.Exception.Message)" + } + } + } + } + } + + return $removedCount +} + +# Remove empty folders +Write-Host "" +Write-Host "Removing empty folders..." -ForegroundColor Yellow +$emptyFoldersRemoved = Remove-EmptyFolders -Path $textureFolderPath -RootPath $textureFolderPath +if ($emptyFoldersRemoved -gt 0) { + Write-Host "Removed $emptyFoldersRemoved empty folder(s)" -ForegroundColor Green +} else { + Write-Host "No empty folders found to remove." -ForegroundColor Gray +} + Write-Host "" Write-Host "File organization complete!" -ForegroundColor Green