To check whether a .csv file exists

Posted by Mahendrabasutkar under Sql Server on 7/11/2011 | Points: 10 | Views : 2307 | Status : [Member] | Replies : 2
How to check whether a .csv file exists in a perticular drive.
Here we do not know file name, but we know only the extension.
We are suppose to do by using sqlserver 2000.



Thanks&Regards
mahendrabasutkar




Responses

Posted by: PandianS on: 7/11/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

If you know the filename then you can use as follows
Create Table #FileStatus

(
FileExists Bit,
FD Int,
Parent Int
)

Insert #FileStatus
EXEC ('xp_fileexist ''E:\DotNetFunda\Funda.sql''')

If Exists(Select 1 from #FileStatus Where FileExists =1)
Print 'The File is available'
Else
Print 'The File is not available'

Drop Table #FileStatus
If you don't know the file name and you have to fetch each file from the folder then you can use
sp_OACreate 

sp_OAGetProperty
sp_OAMethod
sp_OAStop



Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
Declare @MyTable Table(FileNames nvarchar(1000));

insert into @MyTable
exec xp_cmdshell 'dir D:\DirName *.csv /b'

IF EXISTS(select 1 from @MyTable where CHARINDEX('.csv', FileNames)>0 )
PRINT 'CSV File Found'
Else
PRINT 'CSV File Not Found'


Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response