path

回報問題 查看來源 Nightly · 8.4 · 8.3 · 8.2 · 8.1 · 8.0 · 7.6

代表要在存放區中使用的檔案的結構。

成員

basename

string path.basename

提供檔案基本名稱的字串。

目錄名稱

path path.dirname

這個檔案的父項目錄,如果檔案沒有父項,則為 None。 可能會傳回 None

存在

bool path.exists

如果這個路徑表示的檔案或目錄存在,則傳回 true。

請注意,存取這個欄位「不會」導致路徑受到監控。如要讓存放區規則或模組擴充功能對路徑是否存在保持敏感,請在內容物件上使用 watch() 方法。

get_child

path path.get_child(*relative_paths)

傳回將這個路徑與指定相對路徑聯結後取得的路徑。

參數

參數 說明
relative_paths 必要
要附加至這個路徑的零或多個相對路徑字串,並視需要加入路徑分隔符號。

is_dir

bool path.is_dir

如果這個路徑指向目錄,則傳回 true。

請注意,存取這個欄位「不會」導致路徑受到監控。如要讓存放區規則或模組擴充功能判斷路徑是否為目錄或檔案,請在內容物件上使用 watch() 方法。

readdir

list path.readdir(watch='auto')

傳回這個路徑所表示目錄中的項目清單。每個項目本身都是 path 物件。

參數

參數 說明
watch string; default is 'auto'
whether Bazel should watch the list of entries in this directory and refetch the repository or re-evaluate the module extension next time when any changes are detected. 偵測到的變更包括項目建立、刪除和重新命名。請注意,這不會監控目錄中任何項目的內容

可以是 'yes'、'no' 或 'auto' 字串。如果設為 'auto',Bazel 只會在合法情況下監控這個目錄 (詳情請參閱 repository_ctx.watch() 文件)。

realpath

path path.realpath

Returns the canonical path for this path by repeatedly replacing all symbolic links with their referents.