본문 바로가기
반응형

전체 글55

Git 브랜치가 원격과 갈라졌을 때 해결 방법 # Git 브랜치가 원격과 갈라졌을 때 해결 방법 (`diverged` 상황)로컬에서 작업하다 보면 이런 메시지를 만날 수 있습니다:```On branch mainYour branch and 'origin/main' have diverged,and have 1 and 1 different commits each, respectively. (use "git pull" if you want to integrate the remote branch with yours)nothing to commit, working tree clean```이 말은 간단히 정리하면:* 내 로컬 `main` 브랜치에 커밋이 1개 있음* 원격 `origin/main` 브랜치에도 다른 커밋이 1개 있음* 즉, 두 브랜치가 서로 다른 .. 2025. 9. 4.
파이썬 Python 파일명 패턴이 숫자 또는 날짜 형식인 파일만 필터링 # 파일명 패턴이 숫자 또는 날짜 형식인 파일만 필터링 파일명이 `20240505_report.txt` 처럼 날짜/숫자 패턴을 포함할 경우 정규식을 사용할 수 있습니다. import osimport re folder_path = 'C:/Users/username/Documents/myfolder' pattern = re.compile(r'\d{8}_report\.txt') # 예: 20240505_report.txt matched_files = [f for f in os.listdir(folder_path) if pattern.match(f) and os.path.isfile(os.path.join(folder_path, f))] print(matched_files) 날짜 .. 2025. 5. 5.
파이썬 Python 파일 크기 + 확장자 복합 필터링 # 파일 크기 + 확장자 복합 필터링 파일 확장자와 크기 조건을 동시에 만족하는 파일만 가져오려면 아래처럼 조합할 수 있습니다. import os folder_path = 'C:/Users/username/Documents/myfolder' filtered_files = [f for f in os.listdir(folder_path) if f.endswith('.csv') and os.path.getsize(os.path.join(folder_path, f)) > 50000 and os.path.isfile(os.path.join(folder_path, f))] print(filtered_files) 예.. 2025. 5. 5.
파이썬 Python 특정 날짜 이후에 수정된 파일 가져오기 # 특정 날짜 이후에 수정된 파일 가져오기 수정일 기준으로 필터링할 때는 `datetime`과 `os.path.getmtime()`을 함께 사용합니다. import osimport datetime folder_path = 'C:/Users/username/Documents/myfolder'target_time = datetime.datetime(2024, 1, 1).timestamp() # 2024년 1월 1일 이후 recent_files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f)) and os.path.getmtime(os.path.j.. 2025. 5. 5.
파이썬 Python pathlib로 특정 확장자만 필터링 # pathlib로 특정 확장자만 필터링 (.pdf 등) `pathlib`의 `.suffix`를 활용하면 특정 확장자만 걸러낼 수 있습니다. from pathlib import Path folder_path = Path('C:/Users/username/Documents/myfolder') pdf_files = [f for f in folder_path.iterdir() if f.is_file() and f.suffix == '.pdf'] print(pdf_files) 복수 확장자도 (f.suffix in ['.jpg', '.png']) 형태로 걸러낼 수 있어요. 2025. 5. 5.
파이썬 Python pathlib 사용해 폴더 내 모든 파일 가져오기 # pathlib 사용해 폴더 내 모든 파일 가져오기 파이썬 3.4 이상에서는 `pathlib` 모듈을 사용해 더욱 직관적으로 파일 목록을 가져올 수 있습니다. from pathlib import Path folder_path = Path('C:/Users/username/Documents/myfolder') all_files = [f for f in folder_path.iterdir() if f.is_file()] print(all_files) Path.iterdir()은 해당 폴더의 모든 항목을 순회합니다.f.is_file()을 통해 폴더가 아닌 파일만 필터링합니다. 2025. 5. 5.
반응형