Skip to content

Instantly share code, notes, and snippets.

@skysan87
Created September 25, 2019 07:52
Show Gist options
  • Select an option

  • Save skysan87/b8d7dc52798bba27a83b4d924c2b543d to your computer and use it in GitHub Desktop.

Select an option

Save skysan87/b8d7dc52798bba27a83b4d924c2b543d to your computer and use it in GitHub Desktop.
[PowerShell] コピー先のファイル名を指定して、複数個複製するパッチ
REM Drag-and-Drop target file.
powershell -ExecutionPolicy Unrestricted -File %~dp0\copy_file_with_list.ps1 %~dp0\filelist.txt %*
# ファイルリストからファイルを生成するPowerShellスクリプト
# 例: .\copy_file_with_list.ps1 filelist.txt base.txt
# $filelist: ファイルリスト
# $src: コピー元
Param($filelist, $src)
try
{
$baseDir = [IO.Path]::GetDirectoryName($src)
$enc = [Text.Encoding]::GetEncoding("utf-8")
$fh = New-Object System.IO.StreamReader($filelist, $enc)
while (($l = $fh.ReadLine()) -ne $null) {
$newFile = [IO.Path]::Combine($baseDir, $l)
Write-Output newFile
Copy-Item $src $newFile
}
}
catch [Exception]
{
if($fh -ne $null) {
$fh.Close()
}
Write-Output ("Error: $error")
pause
exit 1
}
test.txt
test2.txt
text3.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment