Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check .txt file existence with TSQL?

I have a SP reading a .txt file from File System and using Bulk Insert. I just wanna make sure if file exists before executing bulk insert command. How do i do that?

like image 953
Jango Avatar asked Jan 23 '23 18:01

Jango


1 Answers

try

xp_fileExist ' <file Name> '

The above returns a result set. If you want just a variable, use

declare @FileOK  INT

exec xp_fileExist 'c:\autoexec.bat' ,@FileOK OUTPUT

Print @FileOK
like image 166
Sparky Avatar answered Jan 28 '23 03:01

Sparky