append old organize_textures
This commit is contained in:
53
organize_textures.ps1
Normal file
53
organize_textures.ps1
Normal file
@@ -0,0 +1,53 @@
|
||||
# Script to organize texture files into subdirectories based on their prefix (e.g., Regina_, Martha_)
|
||||
# Usage: .\organize_textures.ps1 (Run from the directory containing the texture files)
|
||||
|
||||
# Get all files (excluding hidden files like .cursorindexingignore)
|
||||
$files = Get-ChildItem -File | Where-Object { $_.Name -notmatch '^\.' };
|
||||
|
||||
# Check if any files were found
|
||||
if ($null -eq $files -or $files.Count -eq 0) {
|
||||
Write-Host "No files found to process (excluding hidden files).";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Group files by their prefix (the part before the first underscore)
|
||||
$groupedFiles = $files | Group-Object { ($_.Name -split '_')[0] };
|
||||
|
||||
# Iterate through each group (prefix)
|
||||
foreach ($group in $groupedFiles) {
|
||||
$prefix = $group.Name;
|
||||
|
||||
# Skip if the prefix is empty or whitespace (shouldn't happen normally, but just in case)
|
||||
if ([string]::IsNullOrWhiteSpace($prefix)) {
|
||||
Write-Warning "Skipping files that result in an empty or whitespace prefix.";
|
||||
foreach ($file in $group.Group) {
|
||||
Write-Warning " Problematic file: $($file.Name)"
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
# Create the subdirectory for this prefix if it doesn't exist
|
||||
if (-not (Test-Path -Path $prefix -PathType Container)) {
|
||||
New-Item -ItemType Directory -Path $prefix | Out-Null;
|
||||
Write-Host "Created directory: $prefix"
|
||||
} else {
|
||||
Write-Host "Directory '$prefix' already exists."
|
||||
}
|
||||
|
||||
# Move each file in the group into the corresponding subdirectory
|
||||
# (Skip if the file is already in the correct directory)
|
||||
foreach ($file in $group.Group) {
|
||||
$destinationDirPath = (Resolve-Path $prefix).ProviderPath;
|
||||
$currentFileDirPath = $file.DirectoryName;
|
||||
|
||||
if ($currentFileDirPath -ne $destinationDirPath) {
|
||||
$destinationPath = Join-Path -Path $prefix -ChildPath $file.Name;
|
||||
Move-Item -Path $file.FullName -Destination $destinationPath -Force;
|
||||
Write-Host "Moved '$($file.Name)' to '$prefix\'"
|
||||
} else {
|
||||
Write-Host "File '$($file.Name)' is already in '$prefix\'"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "File organization complete."
|
||||
Reference in New Issue
Block a user