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)
 Using Xp_filexist

Author  Topic 

schinni
Yak Posting Veteran

66 Posts

Posted - 2004-06-18 : 08:47:48
Hello,

I wanted to see if a file existed in a particular directory or not
i know we can use xp_filexist to find it if you know the file name
is there a way you can use the same to find a file if you don't the file name also Like this.

Xp_fileexist 'C:\Test\*.bat'

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-18 : 08:54:38
Nope. You can use this though.

CREATE TABLE #dir(
dirresults VARCHAR(2000))

INSERT #dir(dirresults)
EXEC master..xp_cmdshell 'dir C:\Test\*.bat /B'

IF (SELECT TOP 1 dirresults FROM #dir) = 'The system cannot find the file specified.'
PRINT 'It ain''t there'
ELSE
PRINT 'You''r in business.'


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

schinni
Yak Posting Veteran

66 Posts

Posted - 2004-06-18 : 09:18:55
is there anything i do without using xp_cmdshell.
Go to Top of Page
   

- Advertisement -