需要学习资源,请点击开挂教学楼
需要学习资源,请点击开挂教学楼
我有一个PowerShell脚本,我正在编写,我需要保留当月的每日备份,一年中的月末备份,并删除除此之外的任何内容。
-
$ThisYear = (Get-Date).year
-
$DailyLogs = (Get-Date).month
-
#Clean-Up Old Backup Files
-
Get-ChildItem 'D:\' | ForEach-Object {
-
if ( $_.LastWriteTime.Year -gt $ThisYear) {
-
Remove-Item
-
}
-
Elsif ( $_.LastWriteTime.Month -gt $ThisMonth -and $_.LastWriteTime.Date -ne ) {
扫描二维码关注公众号,回复: 5741608 查看本文章 -
Remove-Item
-
}
到目前为止,这应该删除任何不是当前年份的备份文件。我试图解决的问题是如何删除除当前月份之后每个月末的备份文件以外的每日备份。我被困在如何获得-ne到任何给定月份的最后一天。
-
#Clean-Up Old Backup Files
-
Get-ChildItem 'D:\Server Backup\' | ForEach-Object {
-
if ( $_.LastWriteTime.Year -gt $ThisYear) {
-
Remove-Item
-
}
-
Elsif ( $_.LastWriteTime.Month -gt $ThisMonth -and $_.LastWriteTime.Date -ne [System.DateTime]::DaysInMonth($_.LastWriteTime.Year, $($_.LastWriteTime.Month))) {
-
Remove-Item
-
}
-
}
基于Lee的评论,这是我的想法。
我用一个 draw
函数在图像中绘制一个矩形。
-
def draw(image, location):
-
...
-
cv2.rectangle(image, ...)
-
return image
由于有很多 locations
矩形,我使用该 map
函数绘制那些矩形。
list(map(lambda x: draw(image, x), locations))
但是,该功能是串行执行的。这意味着速度非常慢。有没有办法在同一图像上平行绘制矩形?
$ThisYear = (Get-Date).year
$DailyLogs = (Get-Date).month
#Clean-Up Old Backup Files
Get-ChildItem 'D:\' | ForEach-Object {
if ( $_.LastWriteTime.Year -gt $ThisYear) {
Remove-Item
}
Elsif ( $_.LastWriteTime.Month -gt $ThisMonth -and $_.LastWriteTime.Date -ne ) {
Remove-Item
}
#Clean-Up Old Backup Files
Get-ChildItem 'D:\Server Backup\' | ForEach-Object {
if ( $_.LastWriteTime.Year -gt $ThisYear) {
Remove-Item
}
Elsif ( $_.LastWriteTime.Month -gt $ThisMonth -and $_.LastWriteTime.Date -ne [System.DateTime]::DaysInMonth($_.LastWriteTime.Year, $($_.LastWriteTime.Month))) {
Remove-Item
}
}
def draw(image, location):
...
cv2.rectangle(image, ...)
return image
list(map(lambda x: draw(image, x), locations))