Hello, i’m completely new to powershell.
I’m trying to make a script where user enter path of a folder (C:\xx). The script in this folder and all subfolders (recursively) must find all files older than x days (x entered by the user). For each file that’s found the script asks user if it wants to be deleted. If user enter “yes”, script actually delete a file.
My problem is that when script asks me if i want to delete file in subfolder (C:\xx\bin) and i enter yes i get error message : Remove-Item : Cannot find path 'C:\xx\bin\demo32.exe because it does not exist. (but it’s actually there). I have this problem only in subfolders…
ps. Sorry for my english
$a = Read-Host "Path of a Folder: " $b = Read-Host "Enter x number: " $c = Get-ChildItem -Path $a -Include *.* -Recurse | Where-Object {$_.LastWriteTime -lt(Get-Date).AddDays(-$b)} foreach ($item in $c) { $decision = Read-Host "Do you want to delete $item ? (yes/no)" if($decision -eq "yes") { Remove-Item -Path $a\$item -Force } }