We sadly lost our original customer and the loss seems irrevocable. Thus, why leave their millions of records in our 10Bn row raw-data table?
So I'm building a somewhat intelligent archival tool, based around bcp as we already use it successfully at our remote SQL Express locations.
The tenet, "First, do no harm" applies here: don't delete anything until you're sure you have a non-zero KB length file in place!
So, having looked at the old xp_cmdshell method and being too lazy to work out if the sp_OA% procedures might help, off to Google-land I trod.
It took an hour or so of looking at other solutions, refining searches, etc., but I came across your SP late yesterday, snagged the code, topped-it with my DBA DB USE, etc., and was delighted to see it compile successfully first time, then run faultlessly to list out SQL Agent Job log files, as a proof of use.
Taking your CREATE TABLE #FileDetails and making it my DECLARE @FileDetails TABLE was an easy clone, and here I am, WHERE EXISTS Path = @mypathandfile AND Size > 0, later, with a solution that fits my exact need.
You have my (continued) admiration for the lengths you must have gone to in order to put this thing together. Beyond that, making it available free gratis and for nowt is highly praiseworthy.
Again, MANY thanks, Jeff.