파이썬 하위 디렉토리 파일크기와 라인 수 추출
소스코드 진단을 위해 실행파일의 크기와 라인 수(개행 포함)를 추출해야 할 일이 생겼다.
코드설명
- 하위 디렉토리 순위.
- 필터 확장자는 Pass. 반대로 필요한 확장자만 역으로도 검색할 수 있다.
- 출력파일은 엑셀에서 ; 구분자로 불러오기 할 수 있다.
import os
def filemtime():
global cnt
global text
os.chdir(path)
with open(filename,'r', errors='replace') as f:
lines = f.readlines()
for cnt, line in enumerate(lines,1):
pass
text = path+';'+filename+';'+ext+';'+str(os.path.getsize(filename))+';'+ str(cnt) + '\n' # sep ';' File
printFile()
def printFile():
global text
with open(outfile, 'a' , errors='replace') as f:
f.write(text)
filters = ('.otf' ) # filter File Name Extension
for (path, dir, files) in os.walk(rootpath): # search rootpath
for filename in files:
ext = os.path.splitext(filename)[-1]
if ext in filters:
pass
else:
filemtime()
'Python > Python for Windows' 카테고리의 다른 글
[Python] Check shared folder of Windows operating system using subprocess and regular expression (0) | 2018.05.04 |
---|---|
[Python] SQLite 메모리DB를 활용한 파이썬 IIS 로그파서 (0) | 2018.04.27 |
[Python] xcopy DOS명령어를 조합한 증분 백업 (0) | 2018.04.20 |
[Python] 윈도우 서버에서 SMTP서버로 메일 발송 (2) (0) | 2018.04.18 |
[Python] 자신의 로컬 IP 알아내기 (0) | 2018.04.18 |
zipfile을 이용한 특정폴더에 있는 모든 파일 압축 (0) | 2018.04.18 |
[Python] 윈도우 netstat 명령어를 활용하여 아웃바운드 IP와 포트 추출 (0) | 2018.04.15 |
[Python] Counters를 이용한 IIS 웹 로그 IP주소 빈도 수 추출 (0) | 2018.04.13 |