Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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 more
Archives
Today
Total
관리 메뉴

Python길라잡이

Python으로 파일을 지우거나 권한을 변경 본문

Python

Python으로 파일을 지우거나 권한을 변경

윤우용 2015. 3. 5. 13:19


import os

os.access ( "tmp"os.R_OK) # 읽기 가능한가? y : True n : False

os.access ( "tmp"os.W_OK) # 쓰기 가능한가? y : True n : False

os.access ( "tmp"os.X_OK) # 실행 가능한가? y : True n : False

os.chmod ( "v.txt", 0755) # 권한 변경

os.remove ( "v.txt") # v.txt 삭제

os.mkdir ( "test") # 디렉터리 만들기

os.listdir ( ".") # 현재 디렉토리의 파일, 디렉토리 목록을 얻을 (li 명령과 동일)

os.system ( "mkdir") #os의 명령 (mkdir은 os.mkdir에서 실행하는 편이 좋다.)

 

import commands

 

print (commands.getoutput ( "ls")) #os 명령을 실행하고 반환 값으로서 명령의 결과를 받는다