Thinkbox Software 製品
ブログ

ファイル名からショット情報を抽出

ファイル名を分割し、ショット情報を求めます

 

記述例(1):os.path.split()を利用しファイル名を分割する

# -*- coding: UTF-8 -*-
import os

inFile = r”X:\project\sequence\shot\image_sequence_####.png”

(head, tail) = os.path.split( inFile )  # 実行結果
# head = ‘X:\project\sequence\shot’
# tail = ‘image_sequence_####.png’

(head, tail) = os.path.split( head )  # 実行結果
# head = ‘X:\project_name\sequence’ shotName = tail
# tail = ‘shot’ – our shot name!

(head, tail) = os.path.split( head )  # 実行結果
# head is now ‘X:\project’ sequenceName = tail
# tail is now ‘sequence’ – our sequence name!

(head, tail) = os.path.split( head )  # 実行結果
# head is now just ‘X:’ projectName = tail
# tail is now ‘project’ – our project name!

 

記述例(2): split()を利用しファイル名を分割する

# -*- coding: UTF-8 -*-
import os

directoryName = “sequence_shot”

splitResult = directoryName.split( “_” ) # アンダースコアーで分割します
sequenceName = splitResult[0]   # 分割された1つ目のパーツ
shotName = splitResult[1]   # 分割された2つ目のパーツ