[Python] Log Gathering
by 담배맛구마생성시간(C_Time)이 전날 06:00부터 오늘 06:00까지의 파일들을 가져온다
import os
import shutil
from time import strftime
from datetime import date, timedelta, datetime
#Get Today and Yesterday
tday = date.today().strftime('%d')
yday = (date.today()-timedelta(1)).strftime('%d')
#Setting################################################################
##[1] Log Directory
logDir = "C:\\LOGS"
##[2] Directory TO Receive Files
dirName = "C:\\"
########################################################################
#Get Time List From Yesterday 06 To Today 05
getLst = ()
for i in range(0, 24):
if i < 6: getLst += (tday+"0"+str(i),)
elif i < 10: getLst += (yday+"0"+str(i),)
else: getLst += (yday+str(i),)
#Calculate Log DirectoryName
logDirSplit = logDir.split("\\")
logDirSplitLen = len(logDirSplit);
#Find Files to send
##[1] Save DirectoryName Having Files
currentDir = ""
##[2] Flag To Check Whether Directory Exists
existDirFlag = 0
##[3] Set BackupDirectoryName
fullDirName = dirName + "\\###LOGS_BACKUP("+yday+"~"+tday+")"
for (path, dirLst, fileLst) in os.walk(logDir):
print(path)
if fileLst:
for f in fileLst:
if datetime.fromtimestamp(int(os.stat(path+"\\"+f).st_ctime)).strftime('%d%H') in getLst:
#Create Directory If Not Exists & Set existDirFlag
if not existDirFlag:
currentDir = fullDirName+"\\"+"\\".join(path.split("\\")[logDirSplitLen:])
os.makedirs(currentDir)
existDirFlag = 1
#Do Copy File
shutil.copy(path+"\\"+f, currentDir)
existDirFlag = 0
반응형
'Dev-' 카테고리의 다른 글
[Python] Geoip를 통한 IP 별 국가코드 매칭 (2) | 2016.07.09 |
---|---|
[Python] PyQT4 ComboBox와 TableWidget 제어 (0) | 2016.04.09 |
[Python] Send Mail by my gmail account (0) | 2016.01.10 |
[Python] PyQT5 기본템플릿비교(Widget, Dialog, Main Window) (0) | 2015.11.14 |
[Python] PyQT5 시작하기 (6) | 2015.10.26 |
블로그의 정보
정윤상이다.
담배맛구마