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

后端 未结 6 1701
抹茶落季
抹茶落季 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:38

    From here:

    function Get-FileAttribute{
        param($file,$attribute)
        $val = [System.IO.FileAttributes]$attribute;
        if((gci $file -force).Attributes -band $val -eq $val){$true;} else { $false; }
    } 
    
    
    function Set-FileAttribute{
        param($file,$attribute)
        $file =(gci $file -force);
        $file.Attributes = $file.Attributes -bor ([System.IO.FileAttributes]$attribute).value__;
        if($?){$true;} else {$false;}
    } 
    

提交回复
热议问题