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 2005 Forums
 Transact-SQL (2005)
 DIR command using xp_cmdshell for a subdirectory

Author  Topic 

jlgervais
Starting Member

3 Posts

Posted - 2010-07-06 : 12:02:55
can't figure this one out, i want to retrieve file names from a particular directory

CREATE PROCEDURE [dbo].[sp_GetFilesInDirectory]
AS
BEGIN
DECLARE @CMD VARCHAR(5000)
DECLARE @Error INT
DECLARE @DirResult TABLE (i INT IDENTITY(1,1) NOT NULL, strData VARCHAR(7000))

--THIS WORKS !
SET @CMD = 'DIR E:\IMPORT'

--Here's the problem, if i set my command to :
SET @CMD = 'DIR E:\IMPORT\TEST'
problem is, as soon as i ask for a subdirectory, i get a "File Not found, there are files in that directory, that command returns two files in a command line window


INSERT INTO @DirResult EXEC @Error = master..xp_cmdshell @CMD
SELECT * FROM @DirResult
END

-- i cannot change the directory, it has to be a subdirectory

thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-06 : 12:26:17
Sorry but I can't see the DIR-command and with only the path it will not work...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jlgervais
Starting Member

3 Posts

Posted - 2010-07-06 : 12:36:44
quote:
Originally posted by webfred

Sorry but I can't see the DIR-command and with only the path it will not work...


No, you're never too old to Yak'n'Roll if you're too young to die.


small mistake while editing my post
still doesn't work, even with the DIR command
Go to Top of Page
   

- Advertisement -