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

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

    $attr = [System.IO.FileAttributes]$attrString
    $prop = Get-ItemProperty -Path $pathString
    # SetAttr
    $prop.Attributes = $prop.Attributes -bor $attr
    # ToggleAttr
    $prop.Attributes = $prop.Attributes -bxor $attr
    # HasAttr
    $hasAttr = ($prop.Attributes -band $attr) -eq $attr
    # ClearAttr
    if ($hasAttr) { $prop.Attributes -bxor $attr }
    

提交回复
热议问题