다음과 같이 복사 명령을 사용하여 두 파일을 결합하고 싶습니다. 이것은 사용하면 충분히 간단합니다.
복사 /b base.txt + file1.txt Combined_file1.txt
그러나 파일의 첫 번째 부분(base.txt)은 그대로 유지되고 두 번째 부분은 다른 파일(예: file1.txt, file2.txt, file3.txt 등)로 가득 찬 폴더에서 가져옵니다.
출력 파일은 다음과 같은 변수 파일 이름이어야 합니다.결합_앞에 추가했습니다.
파일 디렉터리에 배치하고 다른 모든 변수 파일 앞에 base.txt를 자동으로 추가할 수 있는 배치 파일을 원합니다.
답변1
이를 수행하는 Powershell 스크립트는 다음과 같습니다. 기본 경로와 결합된 폴더와 파일 폴더를 조정하면 됩니다.
$baseFilename = "c:\temp\base.txt"
$addonFolderLocation = "c:\temp\files"
$combinedFolderLocation = "c:\temp\combined\"
#Get all files in addon folder location
$addonFilenames = Get-ChildItem $addonFolderLocation
foreach ($addonFilename in $addonFilenames)
{
cat $baseFilename, $addonFilename.fullname | sc "$combinedFolderLocation combined_ $addonFilename"
}
편집: 결합된 출력에서 파일 이름 앞에 결합된_을 추가했습니다.