Hello all, Im currently using the following script:
This code will scan my product table and check each product to see if I have a specific image for it in a local folder. If I do have an image it updates my database and sets the field "image" = 1. It works great except it does not work for products that have dashes in them. Heres a sample product code:
T56-89GH and the actual image file would be named: CompanyName t56 89gh.jpg
My images are all named without dashes and just have spaces in place of the dash but the actual product code in the database still maintains the dash. Let me know if you guys know how to make this work. Thank you.
Code:
CREATE TABLE #files(filename varchar(255)) INSERT INTO #files EXEC master..xp_cmdshell 'dir C:\Inetpub\[URL unfurl="true"]wwwroot\company\html\images\productSpecific\medium1\*.jpg[/URL] /b'
UPDATE P
SET [image] = 1
FROM tblProduct P INNER JOIN
tblCompany C ON P.company = C.ID INNER JOIN
#files F ON F.filename = C.name + ' ' + CONVERT(varchar(6), P.productCode) + '.jpg'
This code will scan my product table and check each product to see if I have a specific image for it in a local folder. If I do have an image it updates my database and sets the field "image" = 1. It works great except it does not work for products that have dashes in them. Heres a sample product code:
T56-89GH and the actual image file would be named: CompanyName t56 89gh.jpg
My images are all named without dashes and just have spaces in place of the dash but the actual product code in the database still maintains the dash. Let me know if you guys know how to make this work. Thank you.