lazypic / OpenPipelineIO

Project Managment Solution
https://docs.openpipeline.io
BSD 3-Clause "New" or "Revised" License
3 stars 4 forks source link

test script #154

Closed khw7096 closed 3 months ago

khw7096 commented 3 months ago
import os

def remove_spaces(root_dir):
    # 모든 디렉토리와 파일에 대해 순회
    for root, dirs, files in os.walk(root_dir, topdown=False):
        # 파일 이름 변경
        for name in files:
            new_name = name.replace(" ", "")
            if new_name != name:
                src = os.path.join(root, name)
                dst = os.path.join(root, new_name)
                if not os.path.exists(dst):
                    os.rename(src, dst)
                else:
                    print(f"Cannot rename {src} to {dst} because the target already exists.")

        # 디렉토리 이름 변경 (파일 변경 후 실행)
        for name in dirs:
            new_name = name.replace(" ", "")
            if new_name != name:
                src = os.path.join(root, name)
                dst = os.path.join(root, new_name)
                if not os.path.exists(dst):
                    os.rename(src, dst)
                else:
                    print(f"Cannot rename {src} to {dst} because the target already exists.")

if __name__ == "__main__":
    # 현재 작업 중인 디렉토리에서 시작
    current_directory = os.getcwd()
    remove_spaces(current_directory)