June 23, 2021 at 3:57 pm
I would approach this differently - I would create a powershell script that removes the empty directories and schedule that to run using the powershell subsystem in SQL Server agent, or as a task on the server.
Get-ChildItem -Directory $backupDirectory | Where-Object {$_.GetFileSystemInfos().Count -eq 0} | Remove-Item
In the script - you would have to define the $backupDirectory and any other variables, but that shouldn't be too hard. If you need to look into SQL Server you can use Invoke-SqlCmd to execute a query and return the results - or use a standard .NET connection strings to setup a call to a stored procedure with parameters.
If you add the -WhatIf parameter to the end...the code runs but doesn't actually remove anything. It just shows you what would happen if you ran the code.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
June 23, 2021 at 6:53 pm
How are you checking that the folder still exists? I've been "caught" more than once by Windows Explorer still displaying the folder until I did a refresh.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 24, 2021 at 7:16 am
@Jeffrey - I did think about using PowerShell but wanted everything to be in one place.
@jeff - That's very strange. Yesterday, I refreshed the parent folder quite a few times and the folder in question was still there.
This morning, it's gone. Looks like Windows was doing something strange and not refreshing correctly (unless it was just taking some time to update the list of folders). If I'm using the code correctly, I'll put it back into play (it's commented out for now while I sorted this out).
June 24, 2021 at 6:48 pm
I figured. You can tell that's "never" happened to me before, right? 😀 Thanks for the feedback. Long live the command line! 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
June 25, 2021 at 7:50 am
Oh, yeah, I can tell 😀
Did it cause you to lose hair as well?
Viewing 5 posts - 31 through 34 (of 34 total)
You must be logged in to reply to this topic. Login to reply