
저는 Windows 10을 사용하고 있습니다.
한 폴더에서 다른 폴더로 많은 파일을 복사하고 싶습니다. 아마도 스크립트나 이를 수행할 수 있는 다른 솔루션이 필요할 것입니다.
2개의 폴더가 있습니다. 폴더에는 A
다음과 같은 이름의 파일이 포함되어 있습니다.
00010_name0_1680x1050.jpg
00020_name11_1680x1050.jpg
00021_name222_1680x1050.jpg
00022_name300_1680x1050.jpg
대상 폴더에는 B
다음과 같은 이름의 파일이 있습니다.
00010_name0_1920x1200.jpg
00020_name11_1920x1200.jpg
00021_name222_1920x1200.jpg
00030_name500_1920x1200.jpg
따라서 파일 이름은 마지막 부분인 해상도가 다르다는 점을 제외하면 동일합니다.
A
모든 파일을 에서 로 복사하고 싶지만 B
이름의 첫 번째 부분이 다르고 마지막까지 _
해상도가 구분되는 파일만 복사하고 싶습니다.
그래서 이름을 비교하고 복사할지 여부를 결정할 수 있는 정규식 스크립트가 필요할 수도 있습니다. 어떤 종류의 간단한 솔루션이라도 감사하겠습니다.
답변1
다음과 같은 종류의 PowerShell 스크립트를 사용할 수 있습니다.
# Save directory paths to vars
$dirA = C:\Some\Folder\A
$dirB = C:\Some\Folder\B
# Get file names of each found .jpg (with 1920x1200 in name)
$fileNamesB = (Get-ChildItem -Path $dirB -Filter *_1920x1200.jpg).Name
# Get prefixes of names that shouldn't be copied, by removing the resolution postfix
# % is shorthand for ForEach-Object
$prefixesB = $fileNamesB | % { $_ -replace "_1920x1200\.jpg$", '' }
$filesA = Get-ChildItem -Path $dirA -Filter *_1680x1050.jpg
# Filter files by checking their name property against our prefixes
# ? is shorthand for Where-Object
$filteredFilesA = $filesA | ? { ($_.Name -replace "_1680x1050\.jpg$", '') -NotIn $prefixesB }
# Copy the filtered files to folder B
$filteredFilesA | Copy-Item -Destination $dirB
기능 설명은 댓글에 있습니다.