Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Changing Image File Reference path

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Changing Image File Reference path

    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.

    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()

    #2
    Re: Changing Image File Reference path

    Preston:

    I do this in the context of a form that contains a drivers license image. I compare the saved value in the image field to what the correct value should be and, when they are different, write the correct value to the image field. The code attached may or may not illuminate your issue. There are some custom functions called. Also, some of the logic also is specific to the business but, even ignoring those pieces of the code, you should be able to see the logic.

    Code:
    function Images_Update as L ( )
    'this function runs in the OnActivate event of the Tickets_Edit form and any
    'tickets edit form which has the dl_image field.
    'It makes sure that the image reference fields are updated if/when/after the
    'application folder has been moved and/or a shadow version of the application
    'is created. The function looks at the image path stored in the field and
    'compares it with the current application path. If the two are not the same (as they should be)
    'the image path in the field is updated with the known image file location and the form
    'is refreshed.
    	on error goto errors
    	
    	dim global app_path as c = SetPathRight()
    	dim global dlimagepath as c = app_path + "Tex-Images" + chr(92) + "Tex-Images" + Chr(92)
    	dim pos1 as n
    	dim get_image as c
    	dim get_image_length as n
    	dim fname as c = ""
    	dim set_image1 as c = "";dim set_image2 as c = "";dim set_image3 as c = ""
    	dim frm as p = parentform.this
    	dim chid as c = alltrim(frm:customer_id.value)
    	'dim tkid as c = alltrim(frm:ticket_number.value)
    	dim t as p = table.current()
    	dim fh as p = t.field_get("dl_image")
    	dim dodlimage as L = .F.;dim do_edit as L = .F.
    	'============================
    	frm.commit()
    	'============================
    	do_dlimage:
    	get_image = fh.value_get()
    	fname = file.filename_parse(get_image,"NE")
    	'===============================
    	'Validate the file name
    	pos1 = at(".",fname)		'if pos1 = 0 there is no period in fname
    	dim lenfname as n = len(alltrim(fname))
    	'the period should be in the fourth position from the right (see the last condition in the if statement below
    	'get the length of the customer id from chid above
    	dim custlen as n = len(chid)
    	if (substr(fname,1,custlen) <> chid) .OR. (right(fname,3) <> "jpg") .OR. (pos1 = 0) .OR. ((lenfname - 3) <> pos1) then	'the filename is not valid
    		'get the proper filename from the subfolder
    		dim flist as c
    		'04/11/2012 Because we were using "*.*" to catch chid + "-001" the filefind get was returning ID's for cans only customers that
    		'were not valid for the ticket. By testing for cans only cutomers and, if true, using ".*" in the filefindget the issue was corrected
    		on error goto nocans
    		if frm:cans_only.value = .T. then			'correct for cans only customers with short Customer ID's
    			flist = filefind.get(dlimagepath + chid + ".*",FILE_FIND_NOT_DIRECTORY+FILE_FIND_NORMAL,"N")
    				else
    					flist = filefind.get(dlimagepath + chid + "*.jpg",FILE_FIND_NOT_DIRECTORY+FILE_FIND_NORMAL,"N")
    		end if
    		nocans:
    		on error goto errors
    		if alltrim(flist) <> "" then
    			if w_count(flist,crlf()) > 1 then
    				fname = word(flist,-1,Crlf())
    					else
    						fname = word(flist,1,Crlf())
    			end if
    		end if
    		else 		'it seems valid
    	end if
    	'===============================
    	'now set the path to the correct app folder location
    	set_image3 = image_filename_encode(dlimagepath + fname)
    	if get_image <> set_image3 then		'apply the new path
    		if file.exists(dlimagepath + fname) then
    			dodlimage = .T.
    			do_edit = .T.
    				else
    					dodlimage = .F.
    					msg_txt = "The requested drivers license file does not exist in " + app_path + "Signatures" + Chr(92)
    					'myl(msg_txt,3)
    		end if
    		else
    			if file.exists(dlimagepath + fname) then
    				else
    					dodlimage = .F.
    					msg_txt = "The requested drivers license file does not exist in " + app_path + "Signatures" + Chr(92)
    					'myl(msg_txt,3)
    			end if
    	End if
    '============================
    	frm.commit()
    	'now set the field values
    	if do_edit then
    		t.change_begin()
    			if dodlimage then
    				fh.value_put(set_image3)
    			end if
    		        	t.change_end(.T.)
    	end if
        frm.resynch()
    END
    
    errors:
    err_msg = error_text_get(error_code_get())
    line = error_line_number_get()
    script = error_script_get()
    LogError(alltrim(err_msg),line,script,A_Form_Current)
    ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
    end
    	
    end function
    '==================================================
    FUNCTION SetPathRight As C ()
    dim this_path as c
    dim bare_path as c
    this_path = A5.Get_Path()
    dim global shadowed as L = .F.
    bare_path = A5.Get_Master_Path()
    if len(alltrim(bare_path)) = 0 then 			'the database is not shadowed
    	shadowed = .F.
    		SetPathRight = this_path + Chr(92)
    			else
    				shadowed = .T.		'only returns true when started from the shadow folder,
    					SetPathRight = bare_path + chr(92)
    end if
    
    END FUNCTION
    Last edited by Finian Lennon; 03-22-2016, 04:58 PM. Reason: line 98 in code changed to "fh.value_put(set_image3)"
    Finian

    Comment


      #3
      Re: Changing Image File Reference path

      Thanks Finian,

      I will take a good look at it tonight or tomorrow and see if it make any sense to me.

      Comment


        #4
        Re: Changing Image File Reference path

        The parts that are critical to understanding what is happening is where the get_image and set_image values are set. In the middle there's some file validation stuff that is probably not relevant to your need.
        Finian

        Comment


          #5
          Re: Changing Image File Reference path

          Just at first glance, so I could be wrong, but the code example you posted seems to be for changing the image file reference in one record from a form. Not what I need to do so I do not know if any of it will work for me yet but I am still looking into it.

          What I am needed to do is change all image file references in several tables where the only change to the image file reference is the drive letter. So C:\Art\Jims Shrimphouse\Staff T-Shirt.jpg would be changed to I:\Art\Jims Shrimphouse\Staff T-Shirt.jpg for example.

          The reason for this is the companies that use my app create a lot of artwork files that can over time grow into the high gigabyte or terabyte range to store all those files so some want to move all their artwork files to another new drive without having to go back through thousands of records and manually change the image file reference.

          So far I have no problem reading all the existing image file reference information and then changing the drive letter to the new one they would specify. Where I am hitting a brick wall is writing the new image file reference information back into the table. Seems you cannot do a read in a while statement and also do a tbl.enter_begin() inside the loop.

          Comment


            #6
            Re: Changing Image File Reference path

            Got it. Just took a few changes to my original code attempt. Changed image_filename_encode(art3_loc) to tbl.art3 = art3_loc.
            Changed tbl.enter_begin(.t.) and tbl.enter_end(.t.) to tbl.change_begin() and tbl.change_end(.T.)

            Still need to do some clean up and add code to close all windows except the main menu before doing this.

            Code for asking the current drive and then the new drive letters.
            Code:
            'Ask for drives
            dim curdrive  as c = "C"
            dim newdrive as c = "C"
            ok_button_label = "&OK"
            cancel_button_label = "&Cancel"
            result=ui_dlg_box("Image Drive",<<%dlg%
            {frame=1,1}
            {region}
            {sp=1}Please select the Current Dive and then New Drive
            {lf};
            {endregion};
            {frame=1,1}
            {region}
            Current Drive:| [.3 curdrive^={C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}];
            New Drive:    | [.3 newdrive^={C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}];
            {lf};
            {endregion};
            {lf};
            {frame=1,1}
            {region}
            <*10=ok_button_label!OK> <*10=cancel_button_label!CANCEL>
            {endregion};
            %dlg%, <<%code%
            IF a_dlg_button = "OK"
            	if curdrive = newdrive then
            		ui_msg_box("Error","New Drive cannot be the same as the Current Drive",UI_OK)
            		a_dlg_button = ""
            		goto done
            		else
                    script_play("cil") 'will change this to a function
                    END IF
            end if        
            DONE:
            %code%)

            Code for changing the image file reference drive letter.
            Code:
            'Backup First
            dim ftime as c 
            dim filelist as c
            dim zipfile as c
            dim zip_path as c
            ftime=ctime(now())
            zipfile = A5.Get_Path()+"\My Backups\\"
            F1=A5.Get_Path()+"\wo_header.*"
            F2=A5.Get_Path()+"\promo_cat.*"
            F3=A5.Get_Path()+"\promo_items.*"
            F4=A5.Get_Path()+"\price_grid.*"
            F5=A5.Get_Path()+"\comp_inf.*"
            zipfile = zipfile+"PreImageMove"+ftime+".zip"
            filelist = f1+crlf()+f2+crlf()+f3+crlf()+f4+crlf()+f5
            ZIP_FILES(zipfile,filelist,.T.,1,"'")
            msg = "Backed up files to "+zipfile+crlf()+" before changing image drive letter"
            ui_msg_box("Notice",msg,UI_NO_SYMBOL)
            	
            'Wo Header
            tbl = table.open("wo_header")
            tbl.index_primary_put("")
            tbl.fetch_first()
            	while .not. eof("wo_header")
            	record = tbl.recno()'Get record number	
            	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 'compair 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 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.change_begin()
            	'tpl.fetch_find(record)' Go to record number
            	if art1_loc >"" then 'If location has changed then write new image reference location to the record
            		tbl.art1 = art1_loc'image_filename_encode(art1_loc)
            	end if
            	if art2_loc >"" then
            		tbl.art2 = art2_loc
            	end if
            	if art3_loc >"" then
            		tbl.art3 = art3_loc
            	end if
            	if art4_loc >"" then
            		tbl.art4 = art4_loc
            	end if
            	if pic_loc >"" then
            		tbl.pic = pic_loc
            	end if
            tbl.change_end(.T.)
            tbl.fetch_next()
            WEND
            tbl.close()
            'Promo Cat
            pic_loc = ""
            tbl = table.open("promo_cat")
            tbl.index_primary_put("")
            tbl.fetch_first()
            	while .not. eof("promo_cat")
            	record = tbl.recno()
            	pic_loc = a5_eval_expression(tbl.pic)
            	picd = substr(pic_loc, 1, 1 )
            	if picd = curdrive then
            	pic_loc = ltrim(pic_loc,curdrive)
            	pic_loc = newdrive+pic_loc	
            	picd = ""
            	end if
            if pic_loc >"" then
            	tbl.change_begin()
            	bl.fetch_find(record)	
            	tbl.pic = pic_loc
            	tbl.change_end(.T.)
            	end if
            tbl.fetch_next()
            WEND
            table.close()
            'Promo Items
            pic_loc = ""
            tbl = table.open("promo_items")
            tbl.index_primary_put("")
            tbl.fetch_first()
            	while .not. eof("promo_items")
            	record = tbl.recno()		
            	pic_loc = a5_eval_expression(tbl.item_pic)
            	picd = substr(pic_loc, 1, 1 )	
            	if picd = curdrive then
            	pic_loc = ltrim(pic_loc,curdrive)
            	pic_loc = newdrive+pic_loc	
            	picd = ""
            	end if
            if pic_loc >"" then
            	tbl.change_begin()
            	bl.fetch_find(record)
            	tbl.item_pic = pic_loc
            	tbl.change_end(.T.)
            	end if
            tbl.fetch_next()
            WEND
            table.close()
            'Price Grid
            pic_loc = ""
            tbl = table.open("price_grid")
            tbl.index_primary_put("")
            tbl.fetch_first()
            	while .not. eof("price_grid")
            	record = tbl.recno()		
            	pic_loc = a5_eval_expression(tbl.pic)
            	picd = substr(pic_loc, 1, 1 )
            	if picd = curdrive then
            	pic_loc = ltrim(pic_loc,curdrive)
            	pic_loc = newdrive+pic_loc	
            	picd = ""
            	end if
            if pic_loc >"" then
            	tbl.change_begin()
            	bl.fetch_find(record)
            	tbl.pic = pic_loc
            	tbl.change_end(.T.)
            	end if
            tbl.fetch_next()
            WEND
            table.close()
            done:
            ui_msg_box("Completed","Drive letter has been changed for the images",UI_NO_SYMBOL)

            Comment


              #7
              Re: Changing Image File Reference path

              Well I found a new twist in all of this. Apparently Alpha does not automatically see an image file reference as being on a master computer if you are also running shadow workstations.

              If you are on the master and reference a image on a local drive then the shadows cannot see it but if you are on a shadow and reference an image back on the master then everyone can see it.

              This sucks..

              So now I need to figure out how to pull \\Master or server\Drive letter or shared name\ and replace it as it is not as simple as just specifying drive letters.

              This is going to be fun.

              Comment


                #8
                Re: Changing Image File Reference path

                Preston,
                Are you saying you can't use a mapped drive letter on the server for this and must specify the full server path?
                Robin

                Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                Comment


                  #9
                  Re: Changing Image File Reference path

                  Originally posted by MoGrace View Post
                  Preston,
                  Are you saying you can't use a mapped drive letter on the server for this and must specify the full server path?
                  You probably could but most don't do that on small intranets. They just use the Windows networking which gives you \\Master or server\Drive letter or shared name\ as the path.

                  Also most of my customers will actually use the master as a computer as well instead of a dedicated server and Windows will not let you map a drive letter to a local drive unless it has been setup as a shared drive on the windows network in which case you would map a drive letter to the windows network path.

                  The other problem I have run into before is Windows will not see a mapped drive letter within a program that has been "Run as Administrator". This is normally not an issue but just something to keep in mind when working with mapped drive letters.

                  What I wanted to do is just create a utility within my app that would allow the moving of graphic files that where referenced from one drive to another drive. The last code I posted above works perfectly but only allows them to select drive letters. The problem of needing to also use a network path arises if that is what they used when setting up the shadows and is what they use when referencing the files.

                  Now I have found and use a utility that allows you to map a local drive letter or folder on a local drive to another drive letter. It works great but you can still run into the issue of Windows not seeing the mapped drive letter if the application is "run as Administrator". Here is a link to that utility. http://www.ntwind.com/software/utili...ual-subst.html

                  Comment


                    #10
                    Re: Changing Image File Reference path

                    Preston,

                    I do this quite a bit in my apps. The key is to use aliases. I don't have a lot of time at the moment to write more...but if you encode the image ref with a alias then you can setup the alias location on your shadow to point to the correct place. You can do the same on the master. Basically, using the alias "pointer" gives you the flexibility to always be able to display the image. See the attached images that show a typical alias setup in "Settings" and then a screenshot where i displayed the encoded image ref path for a record in one of my image tables.

                    AliasSetup.jpgAliasSetup2.jpg

                    Comment


                      #11
                      Re: Changing Image File Reference path

                      Thanks Jeff. I will look into how all that works.

                      Comment

                      Working...
                      X