user8066749
user8066749

Reputation: 61

How can i check whether the filename exist in specific folder

I have the following code to update document path field but i like to check first if the file name is exist on the specified folder or not. if the file exist i would like to update the field with the path otherwise skip the update

My code looks shown below

  use WITESTCO
  update [WITESTCO].[dbo].[WIITEMX] 
  set [docPath]='\\ABC-SERVER\Data\ABC PRODUCTION\DRAWING\2500000 - 2599999 WHL ASSY\PDF\'+[WITESTCO].[dbo].[WIITEMX].[itemId]+'.pdf' FROM [WITESTCO].[dbo].[WIITEMX] where itemId like '2500%' or itemId like '2501%' 

Upvotes: 0

Views: 60

Answers (1)

Ross Bush
Ross Bush

Reputation: 15175

I bet this function will work under normal circumstances.

master.dbo.XP_FileExist 

I know it will work on the local file system of the SQL instance, however, UNC filenames may or may not work. I have not tested.

Upvotes: 1

Related Questions