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 2000 Forums
 Transact-SQL (2000)
 check file extension

Author  Topic 

Rekha
Starting Member

14 Posts

Posted - 2008-03-24 : 06:00:22
Hi,

I have in a requirement to check if there is any file with extension of ".fil" in a folder.
I wrote the query

declare @Path varchar(128) ,
@FileName varchar(128)
select @Path = 'E:\CURRENT_DATA\Processing\' ,
@FileName = 'generic.fil'

declare @i int
declare @File varchar(1000)

select @File = @Path + @FileName
exec master..xp_fileexist @File, @i out
if @i = 1
-- print 'exists'
RAISERROR ('Job "Load all queues" failed as there is .fil file present in processing folder',16,1)

else
print 'not exists'

I dont want to hardcode the file name as there can be any file with extension of .fil, please help me check the way windows search works like *.fil

Thanks in advance

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-24 : 06:14:29
Any particular reason why you want to do this from SQL Server itself? You can easily handle this check from the front-end.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

fahad_001
Starting Member

11 Posts

Posted - 2008-03-24 : 06:54:09
CREATE PROCEDURE Sp_file
@fname as varchar(128)
AS

declare @Path varchar(128) ,
@FileName varchar(128)
select @Path = 'E:\GRLI\images\' ,
@FileName = @fname

declare @i int
declare @File varchar(1000)

select @File = @Path + @FileName
exec master..xp_fileexist @File, @i out
if @i = 1
-- print 'exists'
print 'File exists'

else
print 'not exists'
GO


Just Create a input parameter and pass that file name in store procedure
Go to Top of Page
   

- Advertisement -