How do I change a file's attribute using Powershell?

后端 未结 6 1705
抹茶落季
抹茶落季 2021-02-05 05:07

I have a Powershell script that copies files from one location to another. Once the copy is complete I want to clear the Archive attribute on the files in the source location t

6条回答
  •  暖寄归人
    2021-02-05 05:41

    You may use the following command to toggle the behaviour

    $file = (gci e:\temp\test.txt)
    $file.attributes
    Archive
    
    $file.attributes = $file.Attributes -bxor ([System.IO.FileAttributes]::Archive)
    $file.attributes
    Normal
    
    $file.attributes = $file.Attributes -bxor ([System.IO.FileAttributes]::Archive)
    $file.attributes
    Archive
    

提交回复
热议问题