Skip to content

Instantly share code, notes, and snippets.

@qkdxorjs1002
Last active January 24, 2024 01:35
Show Gist options
  • Save qkdxorjs1002/beb0b194851f0aadc86a1ed7dd87a05c to your computer and use it in GitHub Desktop.
Save qkdxorjs1002/beb0b194851f0aadc86a1ed7dd87a05c to your computer and use it in GitHub Desktop.
디렉터리 경로 생성, 파일 하드링크로 일괄 분할하는 스크립트
import os
import time
from datetime import datetime
### 디렉터리 경로
# 역슬래시는 이중으로
# 예시) = "C:\\NIA_COMPLETE_labeling\\"
sourcePath = "/Users/paragonnov/Documents/org/submit"
# 시작 시간 기록
startTime = time.time()
exceptionLogPath = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") + ".log"
exceptionLog = open(exceptionLogPath, 'a')
beforePath = ""
for path, dirs, files in os.walk(sourcePath):
files = [fi for fi in files if fi.endswith(".json") or fi.endswith(".wav")]
jsonDestPath = path.replace(sourcePath, sourcePath + "-json")
wavDestPath = path.replace(sourcePath, sourcePath + "-wav")
os.makedirs(jsonDestPath, exist_ok=True)
os.makedirs(wavDestPath, exist_ok=True)
for file in files:
srcfilePath = path + "/" + file
if file.endswith(".json"):
destFilePath = jsonDestPath + "/" + file
else:
destFilePath = wavDestPath + "/" + file
if beforePath != path:
print(path)
beforePath = path
try:
os.link(srcfilePath, destFilePath)
except Exception as e:
# 예외 로그에 기록
exceptionLog.write(srcfilePath + "\n err: " + str(e) + "\n")
exceptionLog.close()
print("✅ Job is done.\n")
print("🔴 Running Time:", round(time.time() - startTime, 2), "\bs")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment