[python]os.path.exists() 파일 존재 체크하기

· 13년 전 · 2513

#!/usr/bin/python

import os

if not os.path.exists("./test.txt"):
        print "test.txt file not exist"

if os.path.exists("./test.txt"):
        print "test.text file exist"

root@byoungguk-desktop:~# ./existtest.py 
test.txt file not exist
root@byoungguk-desktop:~# touch test.txt
root@byoungguk-desktop:~# ./existtest.py 
test.text file exist

 
|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
Linux 13년 전 조회 1,726
Linux 13년 전 조회 4,076
Linux 13년 전 조회 1,560
Linux 13년 전 조회 1,467
Linux 13년 전 조회 2,112
Linux 13년 전 조회 2,104
Linux 13년 전 조회 2,156
JavaScript 13년 전 조회 1,996
PHP 13년 전 조회 2,048
JavaScript 13년 전 조회 2,403
jQuery 13년 전 조회 3,635
Linux 13년 전 조회 2,788
Linux 13년 전 조회 1,637
Linux 13년 전 조회 2,281
Linux 13년 전 조회 2,514
Linux 13년 전 조회 2,202
Linux 13년 전 조회 1,772
jQuery 13년 전 조회 3,327
Linux 13년 전 조회 1,509
Linux 13년 전 조회 1,608
Linux 13년 전 조회 1,764
Linux 13년 전 조회 2,213
Linux 13년 전 조회 1,964
jQuery 13년 전 조회 2,311
기타 13년 전 조회 2,781
jQuery 13년 전 조회 3,424
PHP 13년 전 조회 1,887
jQuery 13년 전 조회 8,435
Linux 13년 전 조회 2,725
Linux 13년 전 조회 1,603