March 18, 2005 at 1:16 pm
I am trying to check to see if a file exists before running a copy command via xp_cmdshell. I know that there is xp_fileexists but I am not using it correctly. Any help would be greatly appriciated.
Thanks
Todd
March 18, 2005 at 1:19 pm
>>but I am not using it correctly
Providing details on how exactly you're trying to use it would be a good starting point ...
March 18, 2005 at 1:35 pm
http://www.nigelrivett.net/SQLTsql/CheckIfFileExists.html
and remember that if you plan to access shares you must use unc path instead
hth
* Noel
March 21, 2005 at 6:18 am
To check if a file exists on a disk, I have been using a procedure I found in the Master database: sp_MSget_file_existence
This procedure can be run by all users who have sysadmin rights.
If you are an administrator you can give Exec rights to other users (or to Public).
Example of use:
Declare @Filname nVarChar(260)
Declare @Status Bit
Select @Filname = '\\MyServer\MyDirectory\Myfile.txt'
Exec master..sp_MSget_file_existence @Filname, @Status OUTPUT
If @@Error <> 0 Select @Status = 0
If @Status = 0
Begin
Print 'File not found'
End
Else
Begin
Print 'File found'
End
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply