Any MDF, NDF, or LDF file currently being used by SQL Server cannot be modified in any way. With that in mind (and it would also work if multiple instances had files in a given directory), why not just tell the system to rename them all with a (for example), "NU_" prefix skipping the ones that cannot be renamed? Then, to find all the files that could be moved to an archive or deleted or whatever, just do a DIR "NU_*.*" in the directory and you'll have your list. Same could be done with a Move or Delete command.
The REN command is self-recursive and doesn't stop when it finds a file that is currently in use. For example...
REN *.MDF NU_*.MDF
Only the inactive files will be renamed, if any.
is pronounced "ree-bar
" and is a "Modenism
" for R
First step towards the paradigm shift of writing Set Based code:
________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
"Change is inevitable... change for the better is not".
"Dear Lord... I'm a DBA so please give me patience because, if you give me strength, I'm going to need bail money too!"
How to post code problems
How to Post Performance Problems
Create a Tally Function (fnTally)