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)
 file system object

Author  Topic 

jraha
Starting Member

16 Posts

Posted - 2002-04-25 : 18:02:03
1)
Can you use SQL to interface with an equivalent to the file system object?

2)
Can you do this across servers... I looked into this but was unsuccesful with the SCOPE command (incorrect syntax near "E:\")
SELECT FileName, Size
FROM OpenQuery([linkedserver_name], 'SELECT FileName FROM SCOPE(''"E:\"'') WHERE FileName LIKE ''%.txt%'' ') AS [txtFiles]


3)
Also, presuming I can do this, is it _worth_ doing from a stored procedure (using sp_OACreate and the other set, get, and execute methods) or is this more trouble than it is worth?

Any thoughts?
-Joel

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-25 : 20:08:51
If you just want to list files, you can use the following:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=14855

Depending on what else you need to do (delete, rename, or copy files) you can use xp_cmdshell to execute command-line utilities to accomplish these tasks, pretty much everything that the file system object can do.

If you want to manipulate the contents of a file, you can import and export data from SQL Server into text files using bcp. DTS can also export data to other formats too.

Hope this helps. If there is more you want to do, if you provide more details we may be able to suggest other ways of doing things that don't require using the FileSystemObject. You can definitely use the FileSystemObject in T-SQL with sp_OA if you want, but it might be overkill for some of the more basic operations listed above.

Go to Top of Page
   

- Advertisement -