Как найти изображения по их номерам в файле Excel?

Как найти изображения по их номерам в файле Excel?

У меня есть 1015 изображений в папке, и это изображение классифицировано по семи типам, и эти типы являются категориями медицинских диагнозов рака кожи, и те же изображения классифицированы в файле Excel по номеру (номер каждого изображения соответствует типу диагноза этого изображения). Очевидно, что каждое изображение имеет определенный номер, соответствующий диагностическому типу, мой вопрос заключается в том, как отсортировать эти изображения в папке по группам, чтобы каждая группа изображений имела один и тот же диагноз.

введите описание изображения здесь введите описание изображения здесь введите описание изображения здесь введите описание изображения здесь

решение1

Вы можете попробовать следующий подход в PowerShell. Конечно, его можно оптимизировать, но я хотел, чтобы он был простым для понимания и состоял из 2 шагов: - Первый: создание целевого дерева в соответствии с вашим входным файлом (.csv) - Второй: перемещение файлов изображений в соответствующие подкаталоги)


#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
    }

Будьте осторожны, я не полностью протестировал код, используйте его с осторожностью.

Олив

Связанный контент