일요일 밤에는 코딩을 해야 제 맛
미친 회사가 얼마전 갑자기 주기적 파일 삭제 시스템을 도입했는데,
안 지울 파일은 내일까지 연장 신청해야합니다.
하지만 최근에 이 파일을 사용했는지 살펴봐야할게 무려 2000개...
쌩노가다를 할순 없으니 PC의 모든 파일을 읽어서 최근 조회 년월을 출력하는 프로그램을 하나 만들었네요.
실은 구글신에 검색하니 비슷한게 바로 나와서 살짝만 수정.
사실 제가 15년동안 SAP ABAP만 하다가 파이썬은 올해부터 딥러닝 때문에 하고 있는데,
해보니 아주 쉽고 특히 구글에 웬만한건 다나와서 정말 좋네요.
주변에 A안 주고 나만 써야지.
고생들 해봐라ㅋㅋㅋ
import os
import stat
import time
from datetime import datetime
extlist = ['.xls', '.xlsx', '.ppt', '.pptx', '.doc', '.docx', '.txt', '.jpg']
def getListOfFiles(dirName):
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getListOfFiles(fullPath)
else :
if os.path.splitext(fullPath)[1].lower() in extlist:
allFiles.append(fullPath)
return allFiles
def main():
dirName = 'D:\\MyDocuments';
# Get the list of all files in directory tree at given path
listOfFiles = getListOfFiles(dirName)
# Print the files
for elem in listOfFiles:
df = os.path.split(elem)
fileStatsObj = os.stat ( elem )
accessTime = datetime.strptime(time.ctime( fileStatsObj [ stat.ST_ATIME ] ), "%a %b %d %H:%M:%S %Y")
if accessTime.year >= 2018:
print(str(accessTime.year)+'-'+str(accessTime.month), '\t', df[1],'\t',df[0])
if __name__ == '__main__':
main()
2020-08-02 21:15:02
코로 헤딩하면 코딩인가요?
2020-08-02 21:15:07
그나저나 저 아는 개발자분도 무슨 일만 생기면 코딩으로 해결하던데 진짜 부럽고 대단해보였네요..
2020-08-02 21:28:52
hwp는 왜 없는거죠.. |
글쓰기 |
게시판 오류났나보네요.