April 21, 2009 at 10:56 pm
Hi All
Can anyone please tell me how can i get the name of the images kept in a specified folder on the system through stored procedure in sql server 2005 and 2000.I want to read the name of the images through stored procedure and insert them into a table.
It is very very urgent.Please help me
Thanks in advance
Nothing Is Impossible
April 22, 2009 at 3:57 am
This script will help you...
CREATE TABLE [dbo].[MyDir] (
[Dir] varchar(255)
)
GO
TRUNCATE TABLE MyDir
DECLARE @cmd varchar(4000)
SELECT @cmd = 'Dir c:\*.*'
INSERT INTO MyDir(dir)
EXEC master..xp_cmdshell @cmd
SELECT CONVERT(datetime,SUBSTRING(dir,1,20)) AS [Create_Time]
, CONVERT(int,LTRIM(RTRIM(REPLACE(SUBSTRING(dir,21,19),',','')))) AS [File_Size]
, SUBSTRING(dir,40,(LEN(dir)-39)) AS [File_Name]
, 'FILE'
FROM MyDir
WHERE (SUBSTRING(dir,1,1) ' '
AND SUBSTRING(dir,25,5) CHAR(60)+'Dir'+CHAR(62))
drop table MyDir
Got it from SQLteam and modified it according to the requirement.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply