December 23, 2005 at 11:47 am
Is there a way to create a table and populating it with a listing of filenames for a particular folder? I need to add this type of function to a stored procedure.
Thanks!
December 23, 2005 at 12:29 pm
You can
December 23, 2005 at 12:33 pm
You can use create a table and then run a "dir" or some other mechanism to get a list of files and load into the table. you'd need to then parse things out.
the easiest way is to grab a list of files using something like VBScript and the FileSystemObject and then create a file. You can then load that into sql with DTS, BCP, etc.
December 23, 2005 at 2:20 pm
Thanks for that info! I'll look into this and hopefully get something working. I appreciate it!
December 26, 2005 at 12:13 am
Another possible option...
http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1099668,00.html?track=NL-464&ad=520012
December 27, 2005 at 9:37 am
Try something like this...
Declare
@Dir VarChar(1024),
@Cmd VarChar(8000)
Select
@Dir='C:\WinNT',
@Cmd='Dir /A-D /B "'+@Dir+'"'
If Object_Id('tempdb.dbo.#tmp') is not Null Drop Table dbo.#Tmp
Exec
(
'Create Table dbo.#Tmp(Dir VarChar(1024) default '''+@Dir+''',FN VarChar(256))
Insert dbo.#Tmp (FN)
Exec master.dbo.xp_CmdShell '''+@Cmd+'''
Select * from dbo.#Tmp where FN is not Null'
)
January 2, 2006 at 11:00 am
Very easy to do...
CREATE TABLE #temp (
vchFileName VARCHAR(255)
)
INSERT INTO #temp
EXEC master..xp_cmdshell 'DIR /B C:\WINDOWS'
SELECT * FROM #temp
January 2, 2006 at 3:25 pm
Just a reminder, folks... xp_CmdShell requires SA privs or a proxy login that has SA privs.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy