Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active October 13, 2015 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/5550b5ef60660b3fcbe3 to your computer and use it in GitHub Desktop.
Save kurozumi/5550b5ef60660b3fcbe3 to your computer and use it in GitHub Desktop.
【Python】ディレクトリ内で最も古いCSVファイルを削除する方法
import os
from glob import glob
path = "dir/*.csv"
files = glob(path)
if len(files) > 0:
files.sort(cmp=lambda x, y: int(os.path.getctime(x) - os.path.getctime(y)))
os.remove(files[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment