Attrib

自 Apache Ant 1.6 起.

說明

變更指定目錄內檔案或所有檔案的屬性。目前僅在 Windows 下有效。4 種可能的權限各有其屬性,與 attrib 指令的引數相符。

可以使用巢狀的 <fileset><dirset><filelist> 元素指定 FileSetDirSetFileList

自 Ant 1.7 起,此工作支援任意 資源集合作為巢狀元素。

預設情況下,此工作不會執行任何動作,除非它偵測到它是在 Windows 系統上執行。如果您確定在您的 PATH 上有一個與 Windows 指令相容的 attrib 可執行檔,您可以使用工作的 os 屬性並將其值設定為您目前的作業系統。

請參閱 setpermissions 工作以取得與平台無關的替代方案。

參數

屬性 說明 必要
file 必須變更權限的檔案或目錄。 是,或巢狀的 <fileset/list> 元素
readonly 唯讀權限。 四者中至少一個
archive 封存權限。
system 系統權限。
hidden 隱藏權限。
type 其中之一:filedirboth。如果設定為 file,則只會變更一般檔案的權限。如果設定為 dir,則只會考慮目錄。
注意:type 屬性不適用於巢狀的 dirsetdirset 永遠隱含地假設 type 為 dir
否;預設為 file
verbose 是否在執行後列印摘要。 否;預設為 false
os 可以執行指令的作業系統清單。
osfamily <os> 條件中使用的作業系統系列。 否;預設為 windows

範例

run.bat 檔案成為唯讀且隱藏。

<attrib file="${dist}/run.bat" readonly="true" hidden="true"/>

讓 ${meta.inf} 底下的所有 .xml 檔案可讀。

<attrib readonly="false">
  <fileset dir="${meta.inf}" includes="**/*.xml"/>
</attrib>

讓 ${shared/sources1} 底下的所有檔案(除了任何名為 trial 的目錄底下的檔案)成為唯讀且封存。此外,屬於具有 id other.shared.sources 的 FileSet 的所有檔案都會取得相同的屬性。

<attrib readonly="true" archive="true">
  <fileset dir="shared/sources1">
    <exclude name="**/trial/**"/>
  </fileset>
  <fileset refid="other.shared.sources"/>
</attrib>