Python

os.path 모듈

Yokina 2017. 1. 7. 23:28

os.path 모듈


파일이나 폴더에 대한 정보를 알수 있는 기능

os.path.isdir('c:\\python') #폴더이면 TRUE , 파일이면 False, 폴더없음 False

os.path.isfile('c:\\python\NEWS.txt')  #파일존재 True, 파일아님 False, 파일없음 False

os.path.exists('c:\\python\abc')  #인수의 이름으로 폴더 나 파일이 있으면 True

os.path.getsize('c:\python\test.txt')   #파일의 크기 반환, 폴더는 무조건 4096

os.path.split('c:\\python\\news.txt')   #('c:\\python', 'NEWS.txt')

os.path.splitext('c:\\python\\news.txt')   #('c:\\python\\news', '.txt')

tmpJoin = os.path.split('c:\\python\\news.txt')

print(tmpJoin)  --->   ('c:\\python', 'NEWS.txt')

os.path.join(tmpJoin[0], tmpJoin[1])

os.path.dirname('c:\\python\\readme.txt') # 'c:\\python'

os.path.basename('c:\\python\\readme.txt') # 'readme.txt'