Sign In
🧱 허세 리스트

⏱️ [자동화] 비디오 파일명 일괄변경하기

Huhsame
import os import datetime # 현재 디렉토리의 모든 파일을 나열 files = [f for f in os.listdir('.') if os.path.isfile(f)] for file in files: # 동영상 파일 확장자 확인 if file.lower().endswith(('.mp4', '.avi', '.mov')): # 파일의 생성 시간을 가져옴 created_time = os.path.getctime(file) # 생성 시간을 읽을 수 있는 형식으로 변환 date_time = datetime.datetime.fromtimestamp(created_time) # 새 파일명 형식 (예: '2023-01-01 10-00-00.mp4') new_filename = date_time.strftime('%Y-%m-%d %H-%M-%S') + os.path.splitext(file)[1] # 파일 이름 변경 os.rename(file, new_filename) print(f'Renamed "{file}" to "{new_filename}"')
import os import datetime # 현재 디렉토리의 모든 파일을 나열 files = [f for f in os.listdir('.') if os.path.isfile(f)] for file in files: # 동영상 파일 확장자 확인 if file.lower().endswith(('.mp4', '.avi', '.mov')): # 파일의 메타데이터를 가져옴 file_stats = os.stat(file) # 파일의 'birthtime'을 가져옴 (MacOS에서 사용 가능) birth_time = file_stats.st_birthtime # 생성 시간을 읽을 수 있는 형식으로 변환 date_time = datetime.datetime.fromtimestamp(birth_time) # 새 파일명 형식 (예: '2023-01-01 10-00-00.mp4') new_filename = date_time.strftime('%Y-%m-%d %H-%M-%S') + os.path.splitext(file)[1] # 파일 이름 변경 os.rename(file, new_filename) print(f'Renamed "{file}" to "{new_filename}"')
import os import datetime # Set the path to the directory containing the video file # Since you'll run this on your Mac, you should set this to the path where your video files are located. directory = '/path/to/your/video/files' # The name of the uploaded video file file_name = 'IMG_7016.mov' # Construct the full path to the video file file_path = os.path.join(directory, file_name) # Check if the file exists if os.path.exists(file_path): # Get the birth time of the file file_stats = os.stat(file_path) birth_time = file_stats.st_birthtime # Convert the birth time to a readable format date_time_format = datetime.datetime.fromtimestamp(birth_time).strftime('%Y-%m-%d %H-%M-%S') # Create the new file name with the original file extension new_file_name = f"{date_time_format}{os.path.splitext(file_name)[1]}" # Rename the file os.rename(file_path, os.path.join(directory, new_file_name)) print(f"File renamed to: {new_file_name}") else: print(f"No such file: {file_name}")
import os import datetime # 비디오 파일이 있는 폴더 경로 directory = '/path/to/your/video/files' # 지원하는 비디오 파일 확장자 목록 video_extensions = ('.mp4', '.avi', '.mov', '.mkv') # 폴더의 모든 파일을 나열 files = os.listdir(directory) for file in files: # 파일 확장자 확인 if file.lower().endswith(video_extensions): # 파일의 전체 경로 구성 file_path = os.path.join(directory, file) # 파일의 마지막 수정 시간 가져오기 mod_time = os.path.getmtime(file_path) # 마지막 수정 시간을 읽을 수 있는 형식으로 변환 date_time_format = datetime.datetime.fromtimestamp(mod_time).strftime('%Y-%m-%d %H-%M-%S') # 새 파일명 생성 (원본 확장자 유지) new_file_name = f"{date_time_format}{os.path.splitext(file)[1]}" new_file_path = os.path.join(directory, new_file_name) # 파일 이름 변경 os.rename(file_path, new_file_path) print(f"Renamed '{file}' to '{new_file_name}'")
# 비디오 파일이 있는 폴더 경로 directory = "/Users/huh/Dropbox (Personal)/! New/Youtube/2023.10.31 - 츠케멘
Subscribe to 'huhsame'
Subscribe to my site to be the first to receive notifications and emails about the latest updates, including new posts.
Join Slashpage and subscribe to 'huhsame'!
Subscribe
👍🏻
1