Created
September 25, 2019 07:52
-
-
Save skysan87/b8d7dc52798bba27a83b4d924c2b543d to your computer and use it in GitHub Desktop.
[PowerShell] コピー先のファイル名を指定して、複数個複製するパッチ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| REM Drag-and-Drop target file. | |
| powershell -ExecutionPolicy Unrestricted -File %~dp0\copy_file_with_list.ps1 %~dp0\filelist.txt %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ファイルリストからファイルを生成する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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test.txt | |
| test2.txt | |
| text3.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment