Hello,

I have the following problem. I need to read all files of a specified directory

Problem :

EXEC @hr = sp_OAGetProperty @object_files, 'item', @object_item out, @key=@i

error information :

EXEC sp_OAGetErrorInfo @object_item, @src OUT, @desc OUT
SELECT hrdec=convert(varchar,@hr),hr=convert(varbinary(4) ,@hr), Source=@src, Description=@desc

error : -2147024809
Source error : null
Description error : null

stored procedure :

DECLARE @object int
DECLARE @objectb int
DECLARE @object_folder int
DECLARE @object_files int
DECLARE @object_item int
DECLARE @hr int
DECLARE @property varchar(255)
DECLARE @return varchar(255)
DECLARE @src varchar(255), @desc varchar(255)
DECLARE @a sql_variant

-- Create an object.
print 'creating object'
EXEC @hr = sp_OACreate 'scripting.filesystemobject', @object OUT
IF @hr <> 0
BEGIN
print 'error in creating object'
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END

-- Create an object.
print 'creating objectb'
EXEC @hr = sp_OACreate 'Scripting.Dictionary', @objectb OUT
IF @hr <> 0
BEGIN
print 'error in creating objectb'
EXEC sp_OAGetErrorInfo @objectb, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END

-- Set a property.
print 'creating folder object'

EXEC @hr = sp_OAMethod @object, 'GetFolder', @object_folder out, 'c:\win-r2\import\worldspan'
IF @hr <> 0
BEGIN
print 'error in method getfolder'
EXEC sp_OAGetErrorInfo @object_folder, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END

print 'creating file object'

EXEC @hr = sp_OAMethod @object_folder, 'files', @object_files out
IF @hr <> 0
BEGIN
print 'error in getproperty files'
EXEC sp_OAGetErrorInfo @object_files, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END
print 'loading of files from folder'

declare @i smallint
declare @v1 varchar(4000)
declare @v2 varchar(4000)
declare @v3 varchar(4000)
set @i=1
set @v1 = '1'
EXEC @hr = sp_OAGetProperty @object_files, 'item', @object_item out, @key=@i
IF @hr <> 0
BEGIN
print 'error in getproperty item'
EXEC sp_OAGetErrorInfo @object_item, @src OUT, @desc OUT
SELECT hrdec=convert(varchar,@hr),hr=convert(varbinary(4) ,@hr), Source=@src, Description=@desc
RETURN
END
print @object_item
print @i