Page 1 of 1

save dir

Posted: Thu Apr 14, 2011 8:04 am
by Silvio
when I load a bitmaps the function getdir save on cDir all directory

for sample

c:\work\prg\codici\bitmaps\xxx.bmp

I wish only .\bitmaps\xxx.bmp

because if I insert the exe to another folder or pc it not found the bitmaps

any idea ?

Re: save dir

Posted: Thu Apr 14, 2011 11:36 am
by James Bott
Just save and load the bitmaps to ".\bitmaps\"

James

Re: save dir

Posted: Thu Apr 14, 2011 11:42 am
by Silvio
James,
I have on dialog

@ 40, 10 SAY "Image:" OF oDlg SIZE 21, 8 PIXEL
@ 38, 39 GET aGet[3] var cTabImage OF oDlg SIZE 205, 12 PIXEL

@ 38, 263 BUTTON oBtnSel PROMPT "..." OF oDlg PIXEL SIZE 10, 9 ;
ACTION ( cTabImage:=cGetFile( "*.*", "Select a file" ),;
aGet[3]:refresh())


FUNCTION GetDir( oGet )

LOCAL cFile

cFile := cGetDir32()

IF ! empty( cFile )
oGet:cText := cFile + "\"
ENDIF

RETURN nil


and it take c:\work\prg\codici\bitmaps\xxx.bmp

Re: save dir

Posted: Thu Apr 14, 2011 1:10 pm
by James Bott

Code: Select all

#include "fivewin.ch"

function main()
   local cFile:="c:\work\prg\codici\bitmaps\xxx.bm"

   msgInfo( relativePath( cFile ) )

return nil

Function RelativePath( cFile )
   local cPath, cRelPath, cTemp

   cPath:= cFilePath(cFile)

   cTemp:= left(cPath,len(cPath)-1)

   cRelPath:=  "." + right(cPath, len(cPath) + 1 - rat("\",cTemp) )

return cRelPath

Re: save dir

Posted: Thu Apr 14, 2011 7:13 pm
by Silvio
THIS GIVE ME
.\BITMAPS\
AND NOT
.\BITMAPS\NAMEBMP.BMP

Re: save dir

Posted: Thu Apr 14, 2011 8:58 pm
by ukoenig
Silvio,

You can still add :

relativePath( cFile ) + cFileNoPath( cFile )

to add the Filename.

Best Regards
Uwe :lol:

Re: save dir

Posted: Thu Apr 14, 2011 9:37 pm
by James Bott
Silvio,

I re-read you original message, and you are allowing users to select files from any directory (you are when using cGetFile()), then you need to store the directory with the filename. Using my relative directory will only work if they select files from a subdirectory of the EXE.

If you move the EXE and the data file where you have stored the selected files, (which contains the relative path), files will fail to be found if the user did not select a file from a subdirectory of the original EXE.

I note that the function RelativePath() really has a flaw in that it expects the selected file to be in a subdirectory of the EXE. If the user selects a file from somewhere else, it will return the wrong relative path.

I think the best solution is to store all bitmaps in the .\bitmaps subdirectory of the EXE. If the user selects a bitmap from somewhere else, then you could copy it to the .\bitmaps subdirectory. Then you could just store the filename and hardcode the path ".\bitmaps" in your code.

Alternately, you could not use cGetFile() function and just show a list of all bitmaps in the .\bitmap directory. This would prevent users from loading bitmaps from another location.

You should probably also have an error trap in your code if the bitmap is not found when the EXE is attempting to load it. Upon this error, you could offer the user a chance to select a new bitmap or just provide a default bitmap until the user does want to select one.

James

Re: save dir

Posted: Fri Apr 15, 2011 6:36 am
by Silvio
James ,
I use also for backup or restore this

cPath := cFilePath(GetModuleFileName(GetInstance()))+SUBSTR(cPath,2)

But I not Know where the user take the bitmaps , and I cannot use a BitmapsPath Fix

I try to use the application on another pc but then it not run because on first pc I have a bitmaps into a folder and the 2 pc I have the bitmaps on another folder

I believe it can be usell if the procedure when the user when take the bitmaps save the bitmaps on his folder sample .\bitmaps\ and save on archive the right

path .\bitmaps\namebmp.bmp then the user can use th e application on another pc with no problem