【发布时间】:2015-02-04 19:28:37
【问题描述】:
我可以使用以下代码删除该属性。但是,我不知道如何将日期字符串重新格式化为 ISO 格式。从 date="20140424T140222Z" 到 date="2014-04-24T14:02:22Z"
function update {
$unzippedLocation = Get-ChildItem $destination -Recurse
# from date="20140424T140222Z" to date="2014-04-24T14:02:22Z"
Message "Remove and reformat attributes"
$regex='date="(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z"'
ForEach($unzippedFile in $unzippedLocation) {
(Get-Content $unzippedFile) |
ForEach-Object { $_ -replace ' crc=""', '' } |
ForEach-Object { $_ -replace $regex, 'date="$1-$2-$3T$4:$5:$6Z"' } |
Set-Content $unzippedFile
Write-Host "crc attribute has been removed from $($unzippedFile.Name)"
Write-Host "date attribute has been reformated from $($unzippedFile.Name)"
}
}
【问题讨论】:
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0