python--os

來源:互聯網
上載者:User

標籤:round   並且   span   family   os.path   symlink   etc   --   res   

os.listdir(path=None)

--輸出當前路徑下所有檔案 os.listdir()

#不給參數預設輸出當前路徑下所有檔案 os.stat(path, *, dir_fd=None, follow_symlinks=True)

--#查看檔案狀態資訊 follow_symlinks True返迴文件本身資訊,Flase且如果是軟連結則顯示軟連結本身。

In [9]: os.stat(‘t1‘,follow_symlinks=False)

#如果follow_symlinks指定為False,並且路徑的最後一個元素是符號連結,chmod將修改符號連結本身,而不是連結指向的檔案。

Out[13]: os.stat_result(st_mode=41471, st_ino=1423520, st_dev=64768, st_nlink=1, st_uid=0, st_gid=0, st_size=4, st_atime=1509156724, st_mtime=1509156722, st_ctime=1509156722)

os.chmod(path, mode, *, dir_fd=None, follow_symlinks=True)

--修改許可權 os.chmod(‘test2‘,0o777)

#修改許可權 os.chown(path, uid, gid, *, dir_fd=None, follow_symlinks=True)

--改變檔案的屬主、屬組,但需要有足夠的許可權(root?)

os.chown(‘test2‘,1001,1001)

os.getcwd()#獲得當前工作目錄

os.path.abspath(‘.‘)#獲得當前工作目錄

os.path.abspath(‘..‘)#獲得當前工作目錄的父目錄

os.path.abspath(os.curdir)#獲得當前工作目錄

python--os

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.