Default folder issue

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Default folder issue

Post by Paramvir »

Hi

I defined a path for getfile() function, but it does not honour it. It always open the last directory file path selected. Please see this code:

Code: Select all


CDEFAULTPATH:=diskname() + ":\" + CurDir()+"\PDF_REPORTS\"

cdir :=  GetFile( { { "PDF REPORT FILES", "*.PDF" }} ,;
                        " SELECT PDF REPORT FILE TO OPEN ",CDEFAULTPATH,,.T.)        
What I want is that every time I run this function in my application, i should get the default folder as specified in the variable cdefaultpath. But Getfile() does not honour it and instead, it shows the last directory path actually used. I have tried changing .t. to .f. also but it has no effect. The variable cdefaultpath contains the correct value when i display it. Any idea to solve this issue? Thank you all.
User avatar
dragancesu
Posts: 930
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Default folder issue

Post by dragancesu »

Are cDeafaulPath folder exsist? When not exsist result is unpredictable
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Re: Default folder issue

Post by Paramvir »

dragancesu wrote: Fri Jun 12, 2020 6:48 am Are cDeafaulPath folder exsist? When not exsist result is unpredictable
Thank you Dragancesu.
cDEFAULTPATH, as you see, is a variable name that stores the path I require by using curdir() and a folder named pdf_reports. The folder pdf_reports pre-exists and i created it to store pdf report files. In fact when i retrieve cdefaultpath value, it correctly displays the complete path.
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Default folder issue

Post by AUGE_OHR »

hi,

4th Parameter in your code is missing ... hm
try Demo c:\hmg.3.4.4\SAMPLES\Functions\GETFILE\demo.prg
have fun
Jimmy
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Re: Default folder issue

Post by Paramvir »

AUGE_OHR wrote: Fri Jun 12, 2020 8:12 am hi,

4th Parameter in your code is missing ... hm
try Demo c:\hmg.3.4.4\SAMPLES\Functions\GETFILE\demo.prg
Thank you Auge_Ohr.

As per the HMG Reference, the 4th parameter is for multiselect of files:
/*
Syntax:

GetFile ( acFilter ,
cTitle ,
cDefaultPath ,
lMultiSelect ,
lNoChangeDir ,
nFilterIndex ) --> SelectedFileName(s)
Tips:

- If <lMultiSelect> option is used, a character array containing selected filenames is returned (maximun number of selected files returned is 1024).
- If <lNoChangeDir> option is omitted, default value is .F.
- If passed <nFilterIndex> by reference, will return index of file filter selected by user

*/

So the 4th parameter can be .t. or .f. I gave it .f. and rebuilt the app but still the same issue. The issue is that Getfile function seems to ignore the variable cdefaultpath and just remembers the last folder actually used.
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Re: Default folder issue

Post by Paramvir »

Thank you Dragancesu and Auge_Ohr.

The problem is solved.

A small but costly syntax error on my part:

CDEFAULTPATH:=diskname() + ":\" + CurDir()+"\PDF_REPORTS\"

I shouldn't have used "\" at the end.

Thank you all
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Default folder issue

Post by bpd2000 »

Check with

Code: Select all

// nice function to know current working directory
// usage:

Function Main

 local msg := hb_cwd()
  msginfo(msg ,"Current path: hb_cwd()")
  msginfo(win_GetShortPathName( msg ),"win_GetShortPathName")
  msginfo(hb_dirBase() ,"hb_dirBase() ")
  msginfo(GetStartupFolder(),"GetStartupFolder()")
return nil

FUNCTION win_GetShortPathName( cPath )
   LOCAL cShort := Space(5000)
   wapi_GetShortPathName( cPath, @cShort, Len( cShort) )
RETURN cShort

BPD
Convert Dream into Reality through HMG
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Re: Default folder issue

Post by Paramvir »

bpd2000 wrote: Fri Jun 12, 2020 11:42 am Check with

Code: Select all

// nice function to know current working directory
// usage:

Function Main

 local msg := hb_cwd()
  msginfo(msg ,"Current path: hb_cwd()")
  msginfo(win_GetShortPathName( msg ),"win_GetShortPathName")
  msginfo(hb_dirBase() ,"hb_dirBase() ")
  msginfo(GetStartupFolder(),"GetStartupFolder()")
return nil

FUNCTION win_GetShortPathName( cPath )
   LOCAL cShort := Space(5000)
   wapi_GetShortPathName( cPath, @cShort, Len( cShort) )
RETURN cShort

Thank you. These are indeed very good directory functions.
Post Reply