# Specify the path to Texconv.exe $texconvPath = "C:\path\to\texconv.exe" # Path to the folder with DDS files $sourceFolder = "C:\path\to\dds\files\Folder1" # For example: C:\textures\Folder1 $outputFolder = "C:\path\to\output\folder" $tempOutputFile = Join-Path -Path $outputFolder -ChildPath "temp_output.txt" # Temporary file in the output folder # Ensure the output folder exists if (-not (Test-Path -Path $outputFolder)) { New-Item -Path $outputFolder -ItemType Directory } # Get all DDS files from the folder and subfolders $ddsFiles = Get-ChildItem -Path $sourceFolder -Filter *.dds -Recurse # File processing loop foreach ($file in $ddsFiles) { # Get the filename without extension and convert it to lowercase $fileBaseName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name).ToLower() # Check the current format using texconv and output it to a temporary file & $texconvPath -nologo -dx10 $file.FullName 2>&1 | Out-File -FilePath $tempOutputFile # Read the temp output file $formatCheckOutput = Get-Content $tempOutputFile # Find the line that starts with 'reading' $readingLine = $formatCheckOutput | Where-Object { $_ -like "reading*" } # Check if the reading line contains 'B8G8R8A8_UNORM' if ($readingLine -notlike "*B8G8R8A8_UNORM*") { Write-Host "Skipping file $file.Name: not in B8G8R8A8_UNORM format" continue # Skip this file } # Calculate the relative path from the parent folder "Folder1" to the file $relativePath = $file.FullName.Substring((Get-Item $sourceFolder).Parent.FullName.Length).TrimStart('\') # Path to the output file (preserving the full folder structure) $outputFilePath = Join-Path -Path $outputFolder -ChildPath $relativePath $outputDir = Split-Path $outputFilePath -Parent # Ensure the output directory structure exists if (-not (Test-Path -Path $outputDir)) { New-Item -Path $outputDir -ItemType Directory -Force } # Determine which compression format to use if ($fileBaseName.EndsWith("_ma") -or $fileBaseName.EndsWith("_ct") -or $fileBaseName.EndsWith("_eg") -or $fileBaseName.EndsWith("_mb") -or $fileBaseName.EndsWith("_m")) { $compressionFormat = "BC3_UNORM" } else { $compressionFormat = "BC1_UNORM" } Write-Host "Processing file $file.Name with compression $compressionFormat" # Run texconv with the appropriate parameters and allow overwriting existing files & $texconvPath -f $compressionFormat -y -o $outputDir $file.FullName # Clean up any temporary DDS files accidentally saved near texconv.exe $tempDDSFile = Join-Path -Path (Split-Path $texconvPath -Parent) -ChildPath $file.Name if (Test-Path -Path $tempDDSFile) { Remove-Item -Path $tempDDSFile -Force Write-Host "Deleted temporary file: $tempDDSFile" } } # Delete the temporary output file if it exists if (Test-Path -Path $tempOutputFile) { Remove-Item -Path $tempOutputFile -Force Write-Host "Deleted temporary output file: $tempOutputFile" } Write-Host "All files have been processed!"