I am trying to write a script that will change the Image File Reference path in records within a table.
Running parts of the code in the interactive window for reading the file location, stripping the drive letter off the front and then placing the new drive letter on the file location results in everything being correct.
The problem seems to be I can not get it to write the new location back into the record plus it adds a new record to the table with the first records original image file reference location.
I have beat my head for two days and seem to have hit a mental wall on this. Any suggestions would be appreciated.
Running parts of the code in the interactive window for reading the file location, stripping the drive letter off the front and then placing the new drive letter on the file location results in everything being correct.
The problem seems to be I can not get it to write the new location back into the record plus it adds a new record to the table with the first records original image file reference location.
I have beat my head for two days and seem to have hit a mental wall on this. Any suggestions would be appreciated.
Code:
curdrive = "C" newdrive = "I" 'Wo Header tbl = table.open("wo_header") tbl.index_primary_put("") tbl.fetch_first() while .not. eof("wo_header") art1_loc = a5_eval_expression(tbl.art1)'read the image reference location if art1_loc > "" then 'if a file is referenced art1d = substr(art1_loc, 1, 1 )'get the drive letter if art1d = curdrive then 'compare to current drive letter art1_loc = ltrim(art1_loc,curdrive)'remove drive letter art1_loc = newdrive+art1_loc 'add new drive letter art1d = "" 'reset for next read else art1_loc = "" 'File was referenced but not on current drive and it will not be moved so reset end if end if art2_loc = a5_eval_expression(tbl.art2) if art2_loc > "" then art2d = substr(art2_loc, 1, 1 ) if art2d = curdrive then art2_loc = ltrim(art2_loc,curdrive) art2_loc = newdrive+art2_loc art2d = "" else art2_loc = "" end if end if art3_loc = a5_eval_expression(tbl.art3) if art3_loc > "" then art3d = substr(art3_loc, 1, 1 ) if art3d = curdrive then art3_loc = ltrim(art3_loc,curdrive) art3_loc = newdrive+art3_loc art3d = "" else art3_loc = "" end if end if art4_loc = a5_eval_expression(tbl.art4) if art4_loc > "" then art4d = substr(art4_loc, 1, 1 ) if art4d = curdrive then art4_loc = ltrim(art4_loc,curdrive) art4_loc = newdrive+art4_loc art4d = "" else art4_loc = "" end if end if pic_loc = a5_eval_expression(tbl.pic) if pic_loc > "" then picd = substr(pic_loc, 1, 1 ) if picd = curdrive then pic_loc = ltrim(pic_loc,curdrive) pic_loc = newdrive+pic_loc picd = "" else pic_loc = "" end if end if 'write changes tbl.enter_begin(.t.) if art1_loc >"" then 'If location has changed then write new image reference location to the record tbl.art1 = image_filename_encode(art1_loc) end if if art2_loc >"" then tbl.art2 = image_filename_encode(art2_loc) end if if art3_loc >"" then tbl.art3 = image_filename_encode(art3_loc) end if if art4_loc >"" then tbl.art4 = image_filename_encode(art4_loc) end if if pic_loc >"" then tbl.pic = image_filename_encode(pic_loc) end if tbl.enter_end(.t.) tbl.fetch_next() WEND table.close()
Comment