Hi,
I'm wondering if its possible to return the number of files in a folder suing something like DIR command.
I'm wanting to do something like,
If count(DIR) >0 then do something
Else End
exec master.dbo.xp_cmdshell 'dir C:\Test\'
Technology Tips and News
Hi,
I'm wondering if its possible to return the number of files in a folder suing something like DIR command.
I'm wanting to do something like,
If count(DIR) >0 then do something
Else End
exec master.dbo.xp_cmdshell 'dir C:\Test\'
This article might help:
Hi,
I'm wondering if its possible to return the number of files in a folder suing something like DIR command.
I'm wanting to do something like,
If count(DIR) >0 then do something
Else End
exec master.dbo.xp_cmdshell 'dir C:\Test\'
I think that the xp_cmdshell will definitely work. I've used it before to get the oldest backup and delete it after the new backup completed and was verified. The trick here is:
DIR *.BAK /O /B
The /O switch orders the files and /B reports the file and folder names ONLY (no fluff!)
You could also try:
EXEC master..xp_dirtree 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup', 10, 1