TSQL query to delete all files in a directory using xp

74 views Asked by At

I am trying to delete all the files in specific directory and below is the query I am trying to exec. But its throwing the error as 'invalid parameter'

EXEC master.sys.xp_delete_files '\\nmm\Test\*';

Also I am trying to delete specific specific files with specific file extension too, .csv files like below.

 EXEC master.sys.xp_delete_files '\\nmm\Test\*csv';

Tried

1

There are 1 answers

1
Sergey Olontsev On

Try to define full path to your file, like this:

EXEC master.sys.xp_delete_files 'T:\nmm\Test\*.csv';