Flower in my dev/Python

<PYTHON>[twisted.filepath.FilePath]

꽃선생 2015. 7. 14. 16:06

[filepath.FilePath]

 

파이썬에서 사용하는 file을 확장했다고 봐야할듯..

대상파일이 없어도 인스턴스를 생성할 수 있다.

 

유용한 함수들

- child(something) : something의 결대경로 표시(FilePath형)

- children() : 하위 파일 또는 디렉토리

- touch() : 파일 생성

- makedirs() : 파일 생성(디렉토리)

- create() : 파일 생성(실행)

- remove() : 삭제

- chmod(mode) : mode(int)의 값에 맞게 권한변경

- basename() : 이름

- dirname() : 경로

- realpath() : 경로/이름

- getAccessTime() : 마지막 접근 시간

- exists() : 실제 존내 유무(retrun True or False)

- isdir() : 디렉토리 확인(retrun True or False)

- isfile() : 파일 확인(retrun True or False)

- islink() : 링크 확인(retrun True or False)

- listdir() : 하위 파일 또는 디렉토리 리스트로 반환

- copyTo(dst) : dst에 파일 복사

- moveTo(dst) : dst로 파일 이동

 

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
32
33
34
from twisted.python.filepath import FilePath
 
= FilePath('test')
 
print p
print p.child('test')
print p.children()
print p.listdir()
print p.basename()
print p.dirname()
print p.realpath()
 
new = FilePath('flower')
new.makedirs()
 
print new.exists():
print new.isdir():
print new.isfile():
print new.islink():
 
cm = FilePath('test.txt')
 
print cm.isfile()
 
cm.moveTo(new.child('ok.txt'))
 
print cm.isfile()
 
cm.touch()
 
cm.copyTo(new.child('ko.txt'))
 
print new.children()
print cm.isfile()
cs