I wrote out a simple PowerShell script that backs up a directory to C:
and then deletes any of the backup folders when its age = X days.
For some reason, when I use the Remove-Item
cmdlet I'm getting a Remove-Item: Cannot find path 'C:Windowssystem32 [Sub-Folder name]' because it does not exist
error.
Below is the snippet:
$TargetFolder = "C:Folder"
$Folders = get-childitem -path $TargetFolder
foreach ($Folder in $Folders)
{
remove-item $Folder -recurse -force
}
Within the $TargetFolder = "C:Folder"
, there are a few sub-folders.
Examples: C:FolderSubfolderA
, C:FolderSubfolderB
, etc.
When I do a Write-Host
for $Folder
it lists SubFolderA
, SubFolderB
, etc, correctly so I'm not exactly sure why I'm getting a Cannot find path
error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…