8,330 questions
Try the following:
# Define the root folder path
$rootFolderPath = "C:\Path\to\folder\A"
# Define the maximum age of files to keep (in days)
$maxAgeInDays = 30
# Get the current date
$currentDate = Get-Date
# Define the subfolder path
$subfolderPath = Join-Path -Path $rootFolderPath -ChildPath "B"
# Get files in the subfolder older than the specified age
$filesToDelete = Get-ChildItem -Path $subfolderPath -File | Where-Object {
$_.LastWriteTime -lt ($currentDate.AddDays(-$maxAgeInDays))
}
# Delete the files
foreach ($file in $filesToDelete)
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin