• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

transact sp_OAMethod's parameters for Scripting.FileSystemObject object


I am working with OLE Automation to deal with windows folders and files from inside SQL Server.

I can create an object of type Scripting.FileSystemObject. But when using the stored procedure sp_OAMethod to perform some work on it, I barely know a few parameters as 'FolderExists' or 'CreateFolder'.

I have found some pages like https://msdn.microsoft.com/en-us/library/ch28h2s7(v=vs.84).aspx with provides a description for a set of specific methods of the object for VBScript and JScript, equivalent to use "sp_OAMethod + parameter" in transact.

I would need to find out the same detailed information for transact sp_OAMethod for Scripting.FileSystemObject. Thas is, information of the many parameters for this method and object.

Thanks in advance,

  • 2
1 Solution
Máté FarkasDatabase Developer and AdministratorCommented:
You can do it the following way:
declare @result int;
declare @objectFs int;
declare @folder_exists bit;
declare @folder_name nvarchar(1000) = 'C:\Temp';

exec @result = sp_OACreate N'Scripting.FileSystemObject', @objectFs output;
if @result <> 0 return;
exec @result = sp_OAMethod @objectFs, 'FolderExists', @folder_exists output, @folder_name;
if @result <> 0 return;
if @folder_exists = 0
	exec @result = sp_OAMethod @objectFs, 'CreateFolder', @result output, @folder_name; 

exec sp_OADestroy @objectFs;

Open in new window

Máté FarkasDatabase Developer and AdministratorCommented:
User did not react on a perfect and tested answer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now