LoginSignup
1
0

More than 5 years have passed since last update.

フォルダ上の画像名を連番に変換する

Posted at

はじめに

ダウンロードした画像や頂いた画像タイトルを、連番に変換したい事があります。連番のが後で処理をおこいやすいためです。今回はその時に使用したコードを記載しておきます。

連番に変換

import sys
import os
import re

input_path = <変換前のフォルダ>
output_path = <変換先のフォルダ>

files = os.listdir(input_path)

count = 1
for file in files:

    if file[-4:] == '.jpg': #今回は全てjpgファイルだったのでこの様に指定。バラバラならフォーマットを揃えるスクリプトも必要
        os.rename(input_path+file, output_path+str(count)+'.jpg')
        count = count + 1

わざわざ載せるまでも無い位簡単ですね...

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