Page 1 of 1

Image Path

PostPosted: Wed Sep 05, 2018 11:00 pm
by Silvio.Falconi
On a procedure I must save the Path of Image

the user can select an image from computer and insert on the record

When the procedure save the record , save also the path of the image

I wish have a path like ".\images\fineimage.png"

Where the ".\images\" is the default path sample cPathImage:= ".\images\"

1. How I can have the name of the Image and the extension to save as ".\images\fineimage.png" ?
2. When I save the image the procedure must copy the file image from the folder of Computer where the final user selected the image into cPathImage

Do you have a small test trying to make it ?

Re: Image Path

PostPosted: Fri Sep 07, 2018 8:31 am
by Antonio Linares
Silvio,

1. The returned value of cGetFile() contains the path and filename

Re: Image Path

PostPosted: Fri Sep 07, 2018 8:42 am
by Silvio.Falconi
yes antonio

but I have for a sample C:\Program Files (x86)\EasyBeach\images\image.png

I wish only .\images\image.png

I remember there are some function but I not found it

Now I found on Harbour

hb_PathJoin( "C:\Temp", ".." ) ==> C:\..
hb_PathNormalize( hb_PathJoin( "C:\Temp", ".." ) ) ==> C:\..
hb_PathJoin( "C:\Temp\xxxx", ".." ) ==> C:\Temp\..
hb_PathNormalize( hb_PathJoin( "C:\Temp\xxxx", ".." ) ) ==> C:

but not run ok

Re: Image Path

PostPosted: Mon Sep 10, 2018 2:53 pm
by James Bott
Silvio,

If you already know the full path including the filename, then you can get just the path like this:

cFilePath( "C:\Program Files (x86)\EasyBeach\images\image.png" )

cFilePath() is a built-in function.

I will return: "C:\Program Files (x86)\EasyBeach\images\" (without the quotes).

Is that what you need?

Re: Image Path

PostPosted: Mon Sep 10, 2018 4:33 pm
by James Bott
Silvio,

Or, maybe this is what you want?

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
   Local cImageLocation

   cImageLocation :="C:\Program Files (x86)\EasyBeach\images\image.png"

   msgInfo( myPath(cImageLocation),"myPath(cImageLocation)" )  // returns ".\images\image.png"

Return nil


Function MyPath(cPath)
   Local nNewPath,nPos,nNewPos
   cNewPath:= cFilePath(cPath)
   cNewPath:= left(cNewPath,len(cNewPath)-1) // strip off last \
   nPos:= RAT("\", cNewPath)                 // find pos of 2nd to last \
   nNewPos:= len(cPath) - nPos              
   cNewPath:= "
.\" + right(cPath,nNewPos)
Return cNewPath