January 28, 2010 at 5:51 pm
Hi,
I want to get the list of file names in a folder then pass name as a parameter in a loop.
something like but i m not getting the exact names ! thanks
DECLARE @tabfileNames TABLE (fName varchar(100) )
DECLARE @i int
SET @i=1
INSERT INTO @tabfileNames
exec master.dbo.xp_cmdshell 'dir c:\CIC\.jpg'
while @i <10
begin
select *
from @tabfileNames
set @i=@i+1
January 28, 2010 at 6:25 pm
i think it's just your DIR command:
exec master.dbo.xp_cmdshell 'dir c:\CIC\*.jpg /b'
*.jpg for each jpg file
/b for the brief directory style...just the file name
Lowell
January 28, 2010 at 6:33 pm
Merci beaucoup Lowell !
do you have any suggestion how can I loop to pass names one by name? should I use a cursor or is there any better way?
thanks again .
January 28, 2010 at 6:42 pm
it really depends on what you are doing with the filename; they came into your temp table in a set based operation...could be thousands of file names potentially;
your example did not say what you are doing, it was just selecting the file name one at a time;
what are you trying to do with them? load them as binaries into the database? all via tsql, i think your stuck with looping;
sort them or something/ that'd be set based
Lowell
January 28, 2010 at 6:49 pm
Thanks again Lowell
actually, I need only XML files name to pass them to a script which shred them into sql server.
I already wrote a dynamic script and it works fine. so I just need to loop in the table names and pass them to the dynamic script. Thanks for your help
DECLARE @xmlDoc XML
SET @xmlDoc = (
SELECT * FROM OPENROWSET (
BULK 'C:\bidon\xml_test.xml', SINGLE_CLOB
) AS xmlData
)
SELECT @xmlDoc
January 28, 2010 at 6:53 pm
yep, since openrowset doesn't accept variables,(?right?) you'll be stuck with a cursor to go thru the table of file names, and dynamic SQL to do the openrowset and shredding of the xml; do you need a cursor example, or just a confirmation of your plan?
Lowell
January 28, 2010 at 6:57 pm
Lowell, Yes if you have an example will help for sure. Thanks
January 28, 2010 at 9:48 pm
DECLARE @tbl TABLE
(
File_Names VARCHAR(100)
)
INSERT INTO @tbl
exec master.dbo.xp_cmdshell 'dir c:\*.xml /b'
SELECT * FROM @tbl WHERE File_NamesLIKE'%xml%'
Regards,
Mitesh OSwal
+918698619998
January 29, 2010 at 7:15 am
Thank you very much, I really appreciate it
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply