【发布时间】:2012-02-28 03:25:28
【问题描述】:
我已经编写了一个脚本来删除备份文件,但相信我对存档位属性感到困惑。
$path = "D:\logs\"
$files = Get-ChildItem -Path $path -Recurse
$attribute = [io.fileattributes]::archive #archive bit
$date = get-date -format d # strip time out of date, date needed for Filename
$date = $date.replace('/','.') # strip out forward slashes and replac with . in date
$filename = "\ArchiveLog"+$date+".txt" # Filename for log file.
$location = $path+$filename
cd D:\logs
Foreach($file in $files)
{
If((Get-ItemProperty -Path $file.fullname).attributes -band $attribute)
{
add-content -path "$path" "$file.DirectoryName has been deleted"
Remove-Item $file -force
}
}
但是,当我对此进行测试时,此脚本会删除刚刚创建的全新文件,因为新创建的文件具有“A”属性或存档位。
当我查看其他示例脚本时,它们通常有一行,确保设置了文件存档位:
attribute = [io.fileattributes]::archive #archive bit
If((Get-ItemProperty -Path $file.fullname).attributes -band $attribute)
{
log file name
Remove file
}
所以...我想知道这是否是 Windows 2008 r2 的新功能,其中存档位“A”在创建时自动设置,或者我发现的其他脚本是否错误。
【问题讨论】:
标签: windows powershell attributes archive