tag:crieit.net,2005:https://crieit.net/tags/batch/feed
「batch」の記事 - Crieit
Crieitでタグ「batch」に投稿された最近の記事
2023-02-20T07:35:41+09:00
https://crieit.net/tags/batch/feed
tag:crieit.net,2005:PublicArticle/18390
2023-02-20T07:35:41+09:00
2023-02-20T07:35:41+09:00
https://crieit.net/posts/PowerShell-Powershell
バッチファイルからPowerShellを呼び出し、Powershellコマンドでリネーム
<p><strong>■バッチファイル側</strong><br />
ps_call.bat</p>
<pre><code>@echo off
echo PowerShell呼び出し中です。
powershell -NoProfile -ExecutionPolicy Unrestricted .\rename.ps1
echo 完了しました
pause > nul
exit
</code></pre>
<p><strong>■powershell側</strong><br />
rename.ps1</p>
<pre><code>Set-Location C:\XXXXXX
Get-ChildItem *.txt| Rename-Item -NewName {$_.Name -replace '^([0-9])月','0$1月'}
Get-ChildItem *.txt| Rename-Item -NewName {$_.Name -replace '月([0-9])日','月0$1日'}
Get-ChildItem *.txt| Rename-Item -NewName {$_.Name -replace '([0-9][0-9])月([0-9][0-9])日','$1$2'}
</code></pre>
speasmen88