Excel 파일의 번호를 기준으로 이미지를 어떻게 찾나요?

Excel 파일의 번호를 기준으로 이미지를 어떻게 찾나요?

폴더에 1,015개의 이미지가 있는데 이 이미지를 7가지 유형으로 분류했는데 이 유형이 피부암의 의학적 진단 항목이고, 같은 이미지가 엑셀 파일에 번호별로 분류되어 있습니다(각 사진의 번호는 유형에 해당합니다). 이 이미지의 진단). 분명히 각 이미지에는 진단 유형에 해당하는 특정 번호가 있습니다. 제 질문은 각 이미지 그룹이 동일한 진단을 갖도록 폴더에서 이러한 이미지를 그룹으로 정렬하는 방법입니다.

여기에 이미지 설명을 입력하세요 여기에 이미지 설명을 입력하세요 여기에 이미지 설명을 입력하세요 여기에 이미지 설명을 입력하세요

답변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
    }

조심하세요. 아직 코드를 완전히 테스트하지 않았으니 주의해서 사용하세요.

올리브

관련 정보