Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
|
Lista Forumurilor Pe Tematici
|
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login
POZE MRRRR'S FORUM (VIEW ONLY)
Nu sunteti logat.
|
Nou pe simpatie: Jamieknv 24 ani
 | Femeie 24 ani Bucuresti cauta Barbat 26 - 55 ani |
|
Mrrrr
AdMiN
 Inregistrat: acum 19 ani
Postari: 2374
|
|
I needed powershell script to look inside all the subfolders in a root folder, identify a file named iMDB = X,Y.txt - X and Y are digits - and rename the subfolder containing the txt file with that iMDB rating.
Gemini first gave me a test script to preview the changes before modifying many folders:
# Set path to parent directory containing the subfolders $parentFolder = "C:\Path\To\Your\MainFolder"
Get-ChildItem -Path $parentFolder -Directory | ForEach-Object { $folder = $_ # Look for the IMDb file inside this specific subfolder $imdbFile = Get-ChildItem -Path $folder.FullName -Filter "iMDB = *.txt" | Select-Object -First 1
if ($imdbFile) { # Extract the score (e.g. "7,1" from "iMDB = 7,1.txt") if ($imdbFile.Name -match 'iMDB\s*=\s*([\d,.]+)\.txt') { $score = $matches[1] # Defines the new folder name (e.g., "Movie Name (7,1)") $newName = "$($folder.Name) [$score]"
Write-Host "Would rename: '$($folder.Name)' -> '$newName'" -ForegroundColor Cyan } } else { Write-Host "No IMDb file found in: $($folder.Name)" -ForegroundColor Yellow } } |
And then it gave me the code below to make the actual modifications
$parentFolder = "C:\Path\To\Your\MainFolder"
Get-ChildItem -Path $parentFolder -Directory | ForEach-Object { $folder = $_ $imdbFile = Get-ChildItem -Path $folder.FullName -Filter "iMDB = *.txt" | Select-Object -First 1
if ($imdbFile) { if ($imdbFile.Name -match 'iMDB\s*=\s*([\d,.]+)\.txt') { $score = $matches[1] $newName = "$($folder.Name) [$score]"
# Perform actual folder rename Rename-Item -Path $folder.FullName -NewName $newName Write-Host "Renamed: '$($folder.Name)' to '$newName'" -ForegroundColor Green } } } |
Source: Gemini
_______________________________________

|
|
| pus acum 2 zile |
|