LoginSignup
2
3

More than 5 years have passed since last update.

PowerShellの便利なコマンド

Last updated at Posted at 2018-12-13

ファイル名の数字を加算(減算)してリネームする

「#"数字(3桁)"」で始まるファイル名を対象に、数字(3桁)に「13」を加算して「#"数字(3桁)"-XXX」にリネームする。

$list = ls *.png | % {
    @{
        name = $_.Name;
        num = [Convert]::ToInt32(($_.Name -replace '#([0-9]{1,3}).*.png', '$1')) + 13
    }
}
$list | % { ren $_.name ("#{0:000}-XXX.png" -f $_.num) }

ファイル名を一括してリネームする

拡張子が「.txt」のファイルを「.log」に変更する。

ls *.txt | Rename-Item -newName {$_.Name -replace "\.txt`$",".log"}

ls  "TC*" | ren -NewName {$_.name -replace "TC","#"}

ファイルを一括コピーする

拡張子が「.png」のファイルをカレントディレクトの「aaa」フォルダにコピーする。

copy *.png aaa/

元のファイル名に昇順で数字を追加する

拡張子が「.png」をのファイルを対象に、ファイル名の先頭に"数字(2桁:0埋め)"を追加する。
参考元:https://blog.shibata.tech/entry/2015/11/18/185108


ls *png | sort Name | % {$i = 1} { $NewName = "{0:00}_{1}" -f $i, $_.Name ; mv $_.Name $NewName; $i++ }
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3