環境
- Windows 10
- PowerShell利用可能
- プログラムの実行権限なし
- インストール権限なし
やりたいこと
100個あるディレクトリの名前を以下のように変更したい
before
01_hogehoge/
02_hogehoge/
︙
99_hogee/
test.txt
text.xlsx
after
001_hogehoge/
002_hogehoge/
︙
099_hogee/
test.txt
text.xlsx
やり方
PowerShellで以下のコマンドを当該ディレクトリのある階層に移動して実行する
コード例
Get-ChildItem | ? { $_.Name -match "^[0-9]+.+" } | ? { $_.PSIsContainer } | Rename-Item -NewName { $_.Name -replace "^([0-9]+).*", "0$_" }
おそらくもっと簡単にかけると思うが、とりあえず動いたからヨシ!