=========================================
파일 찾기
import glob
files = glob.glob("*.exe")
print files
=========================================
현재 디렉토리 알기
import os
print os.getcwd()
변경하기
os.chdir("C:/WINDOWS")
print os.getcwd()
경로내 모든 디렉토리 출력
print os.listdir('.')
=========================================
import os,re
루트 디렉토리를 중심으로 하위 폴더 중에서 파일 찾기
os.walk - > 리턴 tuple 형식 ( 경로, 폴더들, 파일들 )
for t in os.walk('Root'):
print t
특정 파일 찾기
def findfile(filepattern, base = '.'):
regex = re.compile(filepattern)
matches = []
for root, dirs, files in os.walk(base):
for f in files:
if regex.match(f):
matches.append(root + '/' + f)
print(matches)
remove(path)
파일 경로를 제거한다.
path가 디렉토리이면, OSError가 일어난다; (디렉토리를 제거하려면 rmdir()을 사용하라).
rename(src, dst)
src 파일이나 디렉토리 dst로 이름을 바꾼다.
dst가 디렉토리이면, OSError가 일어난다.
=========================================
import shutil
copy(src, dst)
src 파일을 dst 파일이나 디렉토리에 복사한다. dst가 디렉토리이면, 지정된 디렉토리에 src와 바탕이름이 같은 파일이 생성된다(즉 오버라이트된다). 허가 비트도 복사된다. src와 dst는 문자열로 주어진 경로 이름이다.
move(src, dst)
재귀적으로 파일이나 디렉토리를 다른 곳으로 이동시킨다.
목적지가 현재 파일시스템이면, 그냥 src의 이름을 바꾸어라. 그렇지 않으면, src를 dst에 복사하고 src를 삭제하라.
=========================================
import os.path as p
import glob
for item in glob.glob('*')
if p.isfile(item): print item, ' is a file'
elif p.isdir(item): print item, ' is a directory'
else: print item, ' is of unknown type'
p.isfile(item)
p.isdir(item)
=========================================
import time as t
t.localtime( )
=========================================
=========================================
=========================================
댓글 없음:
댓글 쓰기