Link to home
Start Free TrialLog in
Avatar of Philippe Renaud
Philippe RenaudFlag for Canada

asked on

SQL see if file exists

Hello EE,

i have a folder where it could contains multiple files...
something like:


EE001.doc
abc.pdf
EE002.doc
EE001.pdf

How can I know if a file or more exists without giving the extension ?

I know there is exec master.dbo.xp_fileexist [@stringname]
but i need to put extension...

here in my example I would like to see that if I search with the name EE001 well it exists because there is a .doc and a .pdf

any idea ? I tried exec master.dbo.xp_fileexist "EE001.*"  but does not work
Avatar of Jared_S
Jared_S

exec master.dbo.xp_fileexist 'C:\Documents and Settings\me\Desktop\EE001.doc'

Should find EE001.doc on your desktop.

The stored procedure does run under the sql user's account, so you may run into problems if you don't have the right security credentials on the network.

Here is a post explaining a work-around that you can try if you need to.

http://www.sqlservercentral.com/Forums/Topic533876-146-2.aspx
Avatar of Philippe Renaud

ASKER

Yes but if I dont type at the end the .doc how can I search the file ?

my question was lets say I dont know the extension is it possible to search with a .* or % for many
I'm sorry, I completely mis-read your question.

Just leave off the extension:

exec master.dbo.xp_fileexist 'C:\Documents and Settings\me\Desktop\EE001'
Avatar of Aneesh
You need to mention typical 8.3 naming conversion

exec master.dbo.xp_fileexist 'C:\Docume~1\me\Desktop\EE001.doc'

try something on C:\

exec master.dbo.xp_fileexist 'C:\EE001.doc'
also, xp_fileExist checks for that file on the server where you installed the sql server and wont check on your local machine. for searching files on the network drives, your sql server service account should have sufficeint permission to see the content of that network folder
ASKER CERTIFIED SOLUTION
Avatar of jonnidip
jonnidip
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
aneeshattingal,
Everything I posted was a result of testing in my environment and my machine is a client.