July 25, 2004 at 10:56 pm
Hi friends,
how to get the filenames from the specified directory using sql server?
very urgent pls...
Regards
-Gopi
July 25, 2004 at 11:21 pm
?? EXEC xp_cmdshell 'dir c:\whatever\'
Derrick Leggett
Mean Old DBA
When life gives you a lemon, fire the DBA.
July 25, 2004 at 11:28 pm
Hi,
But i want to store the filenames in the temporary table. If I pass the value directory from the particular drive...
Regards
-Gopi
July 25, 2004 at 11:42 pm
DECLARE
@directory NVARCHAR(255),
@sql NVARCHAR(2000)
IF (SELECT OBJECT_ID('tempdb..#cmdshell')) IS NOT NULL
BEGIN
DROP TABLE #cmdshell
END
CREATE TABLE #cmdshell(results VARCHAR(8000))
SELECT @directory = 'c:\'
SELECT @sql = 'dir '+ @directory + ' /B /A:-D'
INSERT #cmdshell(results)
EXEC xp_cmdshell @sql
SELECT results FROM #cmdshell
Derrick Leggett
Mean Old DBA
When life gives you a lemon, fire the DBA.
July 25, 2004 at 11:48 pm
July 27, 2004 at 5:06 pm
For a far simpler method, check the answer to one of my past posts,
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=100177
--------------------
Colt 45 - the original point and click interface
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply