Wie finde ich Bilder anhand ihrer Nummern in der Excel-Datei?

Wie finde ich Bilder anhand ihrer Nummern in der Excel-Datei?

Ich habe 1.015 Bilder in einem Ordner und dieses Bild ist in sieben Typen unterteilt und diese Typen sind Kategorien medizinischer Diagnosen von Hautkrebs, und dieselben Bilder sind in der Excel-Datei nach Nummern unterteilt (die Nummer jedes Bildes entspricht der Art der Diagnose dieses Bildes). Natürlich hat jedes Bild eine bestimmte Nummer, die der Diagnoseart entspricht. Meine Frage ist, wie ich diese Bilder im Ordner in Gruppen sortieren kann, sodass jede Bildgruppe dieselbe Diagnose hat.

Bildbeschreibung hier eingeben Bildbeschreibung hier eingeben Bildbeschreibung hier eingeben Bildbeschreibung hier eingeben

Antwort1

Sie können einen Ansatz wie den folgenden in Powershell ausprobieren. Er kann sicherlich optimiert werden, aber ich wollte ihn in zwei Schritten einfach und verständlich gestalten: - Der erste: Erstellen des Zielbaums entsprechend Ihrer Eingabedatei (.csv) - Der zweite: Verschieben von Bilddateien in die entsprechenden Unterverzeichnisse)


#The process : 
$BasedImages = "\\path\to\ImagesDirectory"
$csvfile = "\\path\to\Inputcsvfile.csv"

#Gather all subfolders in the Images Directory (only first level) and put the name of these folder in a var. The only property useful for later use is the Directory name. Useless to gather all properties 
$ExistingSubDir = Get-ChildItem -Path $BasedImages -Directory | Select-Object -Property name

# Gather unique diagnosis in the input file and put in a var. The only useful property in the dx property for a later use. Useless to collect more info. 
$UniqueDiagnosis = Import-Csv -Path $csvfile | Select-Object -property dx -Unique

# gather all images files FullName in the Images Directory and put in a var. it seems that only  Name,DirectoryName, FullName properties will be usefull for later use
$AllImagesFiles = Get-ChildItem -Path $BasedImages -File | Select-Object -Property Name, DirectoryName FullName

# now First Step : build a Tree with  subfolders named by the unique Diagnosis name. 
foreach ($Diagnosis in $UniqueDiagnosis)
    { 
    # search if a diagnosis dir name (dx field in the input .csv file) exist in the ImageDirectory and put the result in a var
    if ($ExistingSubDir -contains $Diagnosis) 
        { 
        Write-Host "$ExistingSubDir is still existing, no action at this step" -ForegroundColor Green 
        }
    else
        {
        New-Item -Path $BasedImages -Name $Diagnosis -ItemType Directory
        Write-Host "a sub-directory named $Diagnosis has been created in the folder $BasedImages" -ForegroundColor Yellow
        }
    }

# At this step, you'll have some sub directories named with the name of all diagnosis (fied dx in the input file)
# Now Step 2 Time to move the files in the root folder
foreach ($image in $AllImagesFiles)
    { 
    $TargetSubDir = Get-Item -Path $($image.fullName)
    Move-Item -Path $($Image.FullName) -Destination ( Join-Path -Path (Split-Path -Path $($Image.DirectoryName) -Parent) -ChildPath $TargetSubDir)
    Write-Host "the image named $($image.name) has been moved to the sud directory $TargetSubDir" -ForegroundColor Green
    }

Achtung, ich habe den Code nicht vollständig getestet, also mit Vorsicht verwenden.

Oliv

verwandte Informationen