Hi!
I noted some discussion about how to determine if a file exists (using a undocumented stored procedure that was available in SQLServer 7, but not in 2000).
Below is a way to handle this, using the windows Scripting object (yes... only valid on a windows platform)
Anyway, here it is; have fun...
====================================================
CREATE PROCEDURE utlFileExists
@sFullFileName varchar(1000)
AS
--
-- Use the windows scripting filesystem
-- object to determine if a file exists...
-- (note: there's some relaxed error handling in here)
-- Hugo Baake
--
-- Return 1 if a file exists, otherwise 0
--
declare @oFS as int
declare @Res as int
exec @Res = sp_OACreate 'Scripting.FileSystemObject', @oFS OUT
if @Res <> 0
begin
RAISERROR ('utlFileExists: error instantiating Scripting.FileSystemObject',1,16)
return
end
exec @Res = sp_OAMethod @oFS, 'FileExists', NULL, @sFullFileName
exec sp_OADestroy @oFS
return @Res
======================================================
I noted some discussion about how to determine if a file exists (using a undocumented stored procedure that was available in SQLServer 7, but not in 2000).
Below is a way to handle this, using the windows Scripting object (yes... only valid on a windows platform)
Anyway, here it is; have fun...
====================================================
CREATE PROCEDURE utlFileExists
@sFullFileName varchar(1000)
AS
--
-- Use the windows scripting filesystem
-- object to determine if a file exists...
-- (note: there's some relaxed error handling in here)
-- Hugo Baake
--
-- Return 1 if a file exists, otherwise 0
--
declare @oFS as int
declare @Res as int
exec @Res = sp_OACreate 'Scripting.FileSystemObject', @oFS OUT
if @Res <> 0
begin
RAISERROR ('utlFileExists: error instantiating Scripting.FileSystemObject',1,16)
return
end
exec @Res = sp_OAMethod @oFS, 'FileExists', NULL, @sFullFileName
exec sp_OADestroy @oFS
return @Res
======================================================