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 2000 Forums
 SQL Server Development (2000)
 sp_OAGetProperty and FileSystemsObject

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-27 : 11:42:39
Yamin Muyal writes "I'm using Windows 2000 Pro (SP2) and SQL Server 2000

I'm trying to use the sp_OA's stored procedures to retrieve a list of the files in a specific folder. Everything goes fine until I try to use the command:
EXEC @hr = sp_OAGetProperty @files, 'Item', @file OUTPUT, @i
to get a pointer to the file. At this moment SQL returns an error without any description.


To reproduce my problem, just paste the code bellow to Query Analyzer and run it:

DECLARE @hr AS int, @fso AS int, @folder AS int, @files AS int, @file AS int
DECLARE @count as int, @i as int
DECLARE @FolderPath AS varchar(255)
DECLARE @src AS varchar(255), @desc AS varchar(255)

SET @FolderPath = 'C:\winnt'
EXEC @hr = sp_OACreate 'Scripting.FileSystemObject', @fso OUT
EXEC @hr = sp_OAMethod @fso, 'GetFolder', @folder OUT, @FolderPath
EXEC @hr = sp_OAMethod @folder, 'Files', @files OUT
EXEC @hr = sp_OAMethod @files, 'Count', @count OUT
print @count -- that works

set @i = 1
EXEC @hr = sp_OAGetProperty @files, 'Item', @file OUTPUT, @i
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @files, @src OUT, @desc OUT
SELECT convert(varbinary(4),@hr) as COD_RETORNO, Source=@src, @desc as MSG_RETORNO
RETURN
END


Any help would be greatly appreciated!

Thanks!"

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-05-27 : 20:11:36
Hi

Is there any reason why you don't just do

Exec Xp_CmdShell 'dir C:\winnt\'


?

Damian
Go to Top of Page
   

- Advertisement -