2014-11-28 5 views
3

방금 ​​파이썬을 배우기 시작했습니다. 어떻게하면 파이썬에서 파일 속성의 상태를 얻을 수 있습니까? 나는 그 os.chmod(fullname, stat.S_IWRITE) readonly 속성을 삭제 알아요,하지만 어떻게 그것을 변경하지 않고 상태를 얻을 수 있습니까? 나는파이썬에서 파일 속성 가져 오기 (숨김, 읽기 전용, 시스템, 아카이브)

+0

운영체제는 리눅스에서 예를 들어 숨김 파일은 이름의 첫 번째 문자로'.'가있는 파일입니다. Windows에서는 파일 속성이라고 생각합니다. –

답변

2

"archive" 당신이 모듈 stat보고 os.stat

os.stat(path) 

Perform the equivalent of a stat() system call on the given path. (This function follows symlinks; to stat a symlink use lstat().) 

The return value is an object whose attributes correspond to the members of the stat structure, namely: 

    st_mode - protection bits, 
    st_ino - inode number, 
    st_dev - device, 
    st_nlink - number of hard links, 
    st_uid - user id of owner, 
    st_gid - group id of owner, 
    st_size - size of file, in bytes, 
    st_atime - time of most recent access, 
    st_mtime - time of most recent content modification, 
    st_ctime - platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows) 
2

당신은 윈도우 API가

처럼 직접 사용할 수 있습니다를 취할 필요가, "hidden", "system", "readonly"의 모든 속성을 얻을 필요
import win32con 
import win32api 
attrs = win32api.GetFileAttributes(filepath) 
attrs & win32con.FILE_ATTRIBUTE_SYSTEM 
attrs & win32con.FILE_ATTRIBUTE_HIDDEN