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
 Transact-SQL (2000)
 Files and folders management

Author  Topic 

madmax1999
Starting Member

2 Posts

Posted - 2005-03-16 : 10:37:40
Hello! I should write a stored procedure that fills a table with folder and file names included in a specified path.

Does anyone know wich Transact-SQL functions should I use or alternatively, how can I use windows API in stored procedure?

Thank you very much, Massimo.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-16 : 10:43:42
use sp_OACreate stored procedure.
see
http://www.nigelrivett.net/SQLTsql/WriteTextFile.html
for more ideas

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-03-16 : 10:49:52
In the past I've done it with something like

CREATE TABLE dbo.ImportDIR
(
Path varchar(8000) NULL
)

INSERT INTO ImportDIR (Filename)
EXEC master.dbo.xp_cmdshell 'dir x:\Mypath\*.* /s /b'

Kristen
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-16 : 10:52:06
that's cool! i always forget you can do that....

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-03-16 : 11:19:07
Yeah, but your whole permissions & hacking thingie might be better covered by using sp_OACreate. its a tad more complicated to build though

Kristen
Go to Top of Page

madmax1999
Starting Member

2 Posts

Posted - 2005-03-16 : 11:28:34

Ok, I saw the books online definition of sp_OACreate but I don't know which object should I create that I could scroll to get my filenames in the directory...

Any suggestion? Thank you 1.000.000! Massimo.
Go to Top of Page
   

- Advertisement -