Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- ASP
- sqlite
- flutter
- javascript
- mssql
- PyQt
- node.js
- Unity
- 날짜
- swift
- PyQt5
- 다이어트
- 라즈베리파이
- 리눅스
- PER
- GIT
- urllib
- ubuntu
- 맛집
- pandas
- port
- MS-SQL
- MySQL
- 유니티
- 함수
- Linux
- tensorflow
- python
- IOS
- Excel
Archives
아미(아름다운미소)
Python directory search and counting by specific extensions 본문
python 디렉토리 전체탐색후 특정확장자별로 카운트하기
# -*- coding: utf-8 -*-
'''
Created on 2018. 9. 5.
@author: bhm
'''
import os
from datetime import datetime
class CGetAllFiles :
def __init__( self ) :
pass
def getFiles( self , recdir ):
x = 0
y = 0
for pack in os.walk(recdir):
for f in pack[2]:
if os.path.splitext(f)[1].lower() =='.wav':
x += 1
if os.path.splitext(f)[1].lower() =='.mp3':
y += 1
print ( ("Dir: %s , there are %s of mp3 files") % ( recdir, str(y) ) )
print ( ("Dir: %s , there are %s of wav files") % ( recdir, str(x) ) )
if __name__ == '__main__':
dt = datetime.now()
dir_Ym = dt.strftime("%Y%m")
dir_Ymd = dt.strftime("%Y%m%d")
org_foldername = u"D:/RecData/한글디렉토리/" + dir_Ym + "/" + dir_Ymd
f = CGetAllFiles()
f.getFiles(org_foldername)
결과 : Dir: D:/RecData/한글디렉토리/201809/20180905/ , there are 3 of mp3 files
Dir: D:/RecData/한글디렉토리/201809/20180905 , there are 2 of wav files
'랭귀지 > python' 카테고리의 다른 글
| python excel 셀에 컬러 입히기 (0) | 2018.09.10 |
|---|---|
| python 엑셀(excel) 다루기 (0) | 2018.09.09 |
| Python에서 확장자가 .wav .mp3 인 디렉토리의 모든 파일 찾기 (0) | 2018.09.07 |
| Python 유용한 os 관련 함수 (0) | 2018.09.06 |
| python 해당시간에 특정작업실행 (0) | 2018.09.05 |
Comments