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

[https://chat.openai.com/share/f61ac1f1-3909-4a6e-8c9a-7322fc82c94d](https://chat.openai.com/share/f61ac1f1-3909-4a6e-8c9a-7322fc82c94d)

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211615_kkwezIYMf24mYUjMNP?q=75&s=1280x180&t=outside&f=webp)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/8cd7c24e-a209-4e8e-aa5e-cfbc5f328644/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/8cd7c24e-a209-4e8e-aa5e-cfbc5f328644/Untitled.png)

```javascript
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}"')
```

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211637_ISkBOZv2RYHJ656VUt?q=75&s=1280x180&t=outside&f=webp)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/db293de9-764e-48ee-a086-a1fd73d443f3/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/db293de9-764e-48ee-a086-a1fd73d443f3/Untitled.png)

```javascript
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}"')
```

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211651_KqsOobzTPg01Q6s0eD?q=75&s=1280x180&t=outside&f=webp)

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211702_mGJOPrJwfogBPogxWf?q=75&s=1280x180&t=outside&f=webp)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/9263e5ea-7d71-4bfc-a01f-42f9de47d60e/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/9263e5ea-7d71-4bfc-a01f-42f9de47d60e/Untitled.png)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/7dbce0e4-6f75-469a-9f77-7ee123e01d63/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/7dbce0e4-6f75-469a-9f77-7ee123e01d63/Untitled.png)

```javascript
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}")

```

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211718_51AhaoBSJEsXqorXIY?q=75&s=1280x180&t=outside&f=webp)

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211726_sSJ0nv5Oyfg5E0kzEi?q=75&s=1280x180&t=outside&f=webp)

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211733_6M5eeZBBPfNUCbyMAH?q=75&s=1280x180&t=outside&f=webp)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/220d5cb9-9953-4bc9-9322-0bedc7f2c3f3/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/220d5cb9-9953-4bc9-9322-0bedc7f2c3f3/Untitled.png)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/e8617261-8e85-41e1-90ad-9f6903e31493/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/e8617261-8e85-41e1-90ad-9f6903e31493/Untitled.png)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/2fedd05e-7bfd-4bd8-9e5b-3b567d9dc0a3/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/2fedd05e-7bfd-4bd8-9e5b-3b567d9dc0a3/Untitled.png)

```javascript
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}'")
```

```javascript
# 비디오 파일이 있는 폴더 경로
directory = "/Users/huh/Dropbox (Personal)/!  New/Youtube/2023.10.31 - 츠케멘
```

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211743_O2PVp6VfhfqUmiE0jc?q=75&s=1280x180&t=outside&f=webp)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/4a2f4af1-0363-4265-81cc-140f28d74c2e/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/4a2f4af1-0363-4265-81cc-140f28d74c2e/Untitled.png)

![https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/114162a0-a0d0-460b-a016-5b580f78226f/Untitled.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/b802779b-16f0-4938-8f07-cbb9f89fc594/114162a0-a0d0-460b-a016-5b580f78226f/Untitled.png)

![Image](https://upload.cafenono.com/image/slashpagePost/20240418/211749_kjpRDDt4Ax3CLsjOyl?q=75&s=1280x180&t=outside&f=webp)

For the site tree, see the [root Markdown](https://slashpage.com/huhsame.md).
