Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Delete File

Author  Topic 

Pete_N
Posting Yak Master

181 Posts

Posted - 2012-03-16 : 10:52:40
I am looping through a directory containing xml files. I set the file name and read the data into a table. This works fine, but after i have finished with the file, I want to delete it but get an error

Could Not Find C:\XMLReports\TEST.XML'

For the reading of the file i set a parameter @FullFile

SET @FullFile = 'C:\XMLReports\' + @FileNAME

It reads the file without a problem, but when i use

SET @Del = 'DEL ' + @FullFile + ''''
EXEC xp_cmdshell @Del
i get the not found error

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-16 : 11:05:25
is file in machine where you runthis command? else you should be using UNC path

\\machinename\...

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Pete_N
Posting Yak Master

181 Posts

Posted - 2012-03-16 : 11:37:19
the files are on the machine that the command runs on. What i dont understand is that my TSQL can see the file to read it but cant see the file to delete it
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-16 : 11:38:25
did you try printing @FullFile value before delete command and check if it has correct value?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Pete_N
Posting Yak Master

181 Posts

Posted - 2012-03-16 : 11:46:19
Its all sorted, had an extra quote at the end of the file name !
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-16 : 11:53:33
quote:
Originally posted by Pete_N

Its all sorted, had an extra quote at the end of the file name !


i guessed it will be some kind of simple issue in the end!
it has happened to me a lot!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -