我有一个名为Videos的目录。在这个目录中,有许多不同相机的子目录。我有一个脚本,将检查每个相机,并删除早于某个日期的录像。
我在获取相机的完整目录信息方面遇到了一些问题。我使用以下代码来获取它:
有没有办法将@{FullName=}从路径中去掉?我认为这可能是问题所在。
我在获取相机的完整目录信息方面遇到了一些问题。我使用以下代码来获取它:
#Get all of the paths for each camera
$paths = Get-ChildItem -Path "C:\Videos\" | Select-Object FullName
然后我循环遍历$paths中的每个路径并删除我需要的内容:
foreach ($pa in $paths) {
# Delete files older than the $limit.
$file = Get-ChildItem -Path $pa -Recurse -Force | Where-Object { $_.PSIsContainer -and $_.CreationTime -lt $limit }
$file | Remove-Item -Recurse -Force
$file | Select -Expand FullName | Out-File $logFile -append
}
当我运行脚本时,出现如下错误:
@{FullName=C:\Videos\PC1-CAM1}
Get-ChildItem : Cannot find drive. A drive with the name '@{FullName=C' does not exist.
At C:\scripts\BodyCamDelete.ps1:34 char:13
+ $file = Get-ChildItem -Path $pa -Recurse -Force | Where-Object { $_.PSIsCont ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (@{FullName=C:String) [Get-ChildItem], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
有没有办法将@{FullName=}从路径中去掉?我认为这可能是问题所在。