標籤:http itext file gets pytho val ber 檔案大小 存在
全部函數可以用help(os)或是dir(os)查看其用法。 1.重新命名:os.rename(old, new)2.刪除:os.remove(file)3.列出目錄下的檔案 :os.listdir(path)4.擷取當前工作目錄:os.getcwd()5.改變工作目錄:os.chdir(newdir)6.建立多級目錄:os.makedirs(r"c:\python \test")7.建立單個目錄:os.mkdir("test")8.刪除多個目錄:os.removedirs(r"c:\python") #刪除所給路徑最後一個目錄下所有空目錄。9.刪除單個目錄:os.rmdir("test")10.擷取檔案屬性:os.stat(file)11.修改檔案許可權與時間戳記:os.chmod(file)12.執行作業系統命令:os.system("dir")13.啟動新進程:os.exec(), os.execvp()14.在後台執行程式:osspawnv()15.終止當前進程:os.exit(), os._exit()16.分離檔案名稱:os.path.split(r"c:\python\hello.py") --> ("c:\\python", "hello.py")17.分離副檔名:os.path.splitext(r"c:\python\hello.py") --> ("c:\\python\\hello", ".py")18.擷取路徑名:os.path.dirname(r"c:\python\hello.py") --> "c:\\python"19.擷取檔案名稱:os.path.basename(r"r:\python\hello.py") --> "hello.py"20.判斷檔案或目錄是否存在:os.path.exists(r"c:\python\hello.py") --> True21.判斷是否是絕對路徑:os.path.isabs(r".\python\") --> False22.判斷是否是目錄:os.path.isdir(r"c:\python") --> True23.判斷是否是檔案:os.path.isfile(r"c:\python\hello.py") --> True24.判斷是否是連結檔案:os.path.islink(r"c:\python\hello.py") --> False25.擷取檔案大小:os.path.getsize(filename)26.搜尋目錄下的所有檔案:os.path.walk() ps:本文轉自 http://wangwei007.blog.51cto.com/68019/1217082 王偉,感謝作者
python 檔案操作 os