Windows 7では、これをPowerShellの1行で実行できます。
powershell -C "gci | % {rni $_.Name ($_.Name -replace '120x90', '67x100')}"
説明
powershell -C "..."
は、引用符で囲まれたコマンドを実行するためのPowerShellセッションを起動します。コマンドが完了すると、外部シェルに戻ります。 -C
は-Command
の略です。
gci
は、現在のディレクトリにあるすべてのファイルを返します。 Get-ChildItem
の別名です。
| % {...}
は、各ファイルを処理するパイプラインを作成します。 %
はForeach-Object
の別名です。
$_.Name
は、パイプライン内の現在のファイルの名前です。
($_.Name -replace '120x90', '67x100')
は、-replace
演算子を使用して新しいファイル名を作成します。第1の部分文字列の各出現は、第2の部分文字列に置き換えられる。
rni
は、各ファイルの名前を変更します。最初のパラメータ(-Path
)はファイルを識別します。 2番目のパラメータ(-NewName
)は、新しい名前を指定します。 rni
はRename-Itemの別名です。
例
$ dir
Volume in drive C has no label.
Volume Serial Number is A817-E7CA
Directory of C:\fakedir\test
11/09/2013 16:57 <DIR> .
11/09/2013 16:57 <DIR> ..
11/09/2013 16:56 0 750_MOT_Forgiving_120x90.jpg
11/09/2013 16:57 0 751_MOT_Persecution_1_120x90.jpg
11/09/2013 16:57 0 752_MOT_Persecution_2_120x90.jpg
3 File(s) 0 bytes
2 Dir(s) 243,816,271,872 bytes free
$ powershell -C "gci | % {rni $_.Name ($_.Name -replace '120x90', '67x100')}"
$ dir
Volume in drive C has no label.
Volume Serial Number is A817-E7CA
Directory of C:\fakedir\test
11/09/2013 16:57 <DIR> .
11/09/2013 16:57 <DIR> ..
11/09/2013 16:56 0 750_MOT_Forgiving_67x100.jpg
11/09/2013 16:57 0 751_MOT_Persecution_1_67x100.jpg
11/09/2013 16:57 0 752_MOT_Persecution_2_67x100.jpg
3 File(s) 0 bytes
2 Dir(s) 243,816,271,872 bytes free
窓や何の.batまたは.cmdのファイルで動作しますか? – Blainer
あなたが助けを望むならば、みんなが霊的であることを期待することはできません。 –