如何使用 Powershell 更改文件的属性? [英] How do I change a file's attribute using Powershell?
本文介绍了如何使用 Powershell 更改文件的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Powershell 脚本,可以将文件从一个位置复制到另一个位置.复制完成后,我想清除源位置中已复制文件的存档属性.
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 that have been copied.
如何使用 Powershell 清除文件的存档属性?
How do I clear the Archive attribute of a file using Powershell?
推荐答案
来自 此处:
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;}
}
这篇关于如何使用 Powershell 更改文件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文