파일이 일대일로 일치한다고 가정합니다.
# Get contents of file 1
$File1 = Get-Content -Path $PSScriptRoot\File1.txt;
# Get contents of file 2
$File2 = Get-Content -Path $PSScriptRoot\File2.txt;
# Iterate over each item in $File1
foreach ($Item in $File1) {
$FileList = Get-ChildItem -Path "c:\test\$Item*.jpg";
foreach ($File in $FileList) {
# Determine file's new name, based on corresponding value in File2
$NewName = $File.Name -replace $Item, $File2[$File1.IndexOf($Item)];
Write-Host -Object ('Old name: {0}, new name: {1}' -f $Item, $NewName);
}
}
두 목록을 서로 연결할 수 있습니까? 1234c는 파일 1의 단일 레코드 (abc1234cd.jpg) 만 참조합니다. 이 두 가지 객체를 결합하는 데는 여러 가지 방법이 있습니다. 사람들은 재현 할 수있는 사용자 정의 Join-Object 함수를 작성했습니다. 하지만 그것은 두 배열이 일치 할 수 있는지에 달려 있습니다. – websch01ar
실제로 abc1234cd.jpg가 abc1234cd2.jpg 일 수있는 상황이있을 수 있습니다. 1234c.jpg와 1234c-1로 이름을 바꿀 필요가 있습니다. 1234c-1.jpg에 1234c가 포함되어 있기 때문에 증분으로. – user3225168