0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

バッチファイルで画像を順番にリネームして保存する方法

Posted at

【記事の概要】

この記事では、バッチファイルを使ってPCフォルダ内の画像を順番にリネームしていく方法について説明しています。

【メリット】

今まで手動で1つずつファイル名を変更していましたが、このバッチを使えば大量の画像ファイルを一瞬で変更できるようになります。

【手順】

  1. 画像をフォルダに移動: まず、整理したい画像を一つのフォルダに集めます。
  2. メモ帳を開く: 提供されたバッチファイルのコードをコピーします。
  3. コードのカスタマイズ: フォルダのパスを自分の環境に合わせて変更します。
  4. バッチファイルとして保存: コードをバッチファイル(.bat)として保存します。
  5. バッチファイルを実行: 保存したバッチファイルをダブルクリックして実行します。

bat
@echo off			
setlocal enabledelayedexpansion			
			
cd /d "C:\Users\onecl\Desktop\test"			
set /a "count=0"			
			
for /f "delims=" %%f in ('dir /b /a-d /od *.webp') do (			
set "filename=image-!count!.webp"			
ren "%%f" "!filename!"			
set /a "count+=1"			
)

【各コードの簡単な説明】

@echo off:コマンドの実行結果以外を表示しないようにします。
setlocal enabledelayedexpansion:変数の遅延展開を有効にし、ループ内で変数の値を動的に更新できるようにします。
cd /d "C:\Users\onecl\Desktop\test": 画像ファイルが保存されているディレクトリに移動します。このパスは、実際のフォルダの場所に応じて適宜変更してください。
set /a "count=0": リネームしたファイルのカウント用の変数を0に初期化します。
for /f "delims=" %%f in ('dir /b /a-d /od *.webp') do (...): フォルダ内の.webp形式の画像ファイルを古い順に処理するためのループを作成します。delims=は区切り文字を指定しないことを意味し、ファイル名にスペースが含まれていても正しく処理されます。
ren "%%f" "!filename!": 各画像ファイルをimage-番号.webpの形式にリネームします。!count!変数を使って、リネームするたびにファイル名に連番を付けていきます。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?