Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using FullPath() or SetPath() with GetFile()

Status
Not open for further replies.

txgeekgirl1

Programmer
Sep 10, 2009
85
US
I have stupid users so I need to help them as much as possible to get where they need to be. I have a GETFILE() which does allow the EU to choose a file but they have to navigate our network to get to the correct folder. Is there a way to conjuctively use the FullPath() or SetPath() functions with GetFile()?
 
GetFile starts in the (C)urrent (D)irectory, so you can CD or SET DEFAULT to the folder of interest before doing GETFILE().

Bye, Olaf.
 
so you can CD or SET DEFAULT to the folder of interest before doing GETFILE().

Always keeping in mind that that'll change the default directory as seen by the rest of your application. So you need to save the current default to a variable and restore it afterwards.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I have found that out. Trying to find a graceful way to restore. Here's what I am testing:

CD("F:\Encounter")

WhatFile = GETFILE("TEXT:TXT", "Import File:", "Select", 0, ;
"Please choose the Import File for this report")
IF EMPTY(WhatFile)
*-- FF does not print empty cursors
SELECT 0
CREATE CURSOR MRPWDET_ (Dummy C(10))
RETURN
ELSE
RD("F:\Encounter)
CD("rbas\Iserv_Test\progs")
 
Well, remember Fullpath(Curdir() in a variable and set it back afterwards.

Bye, Olaf.
 
OK - I need help. How can I call it back without bombing?

STORE FULLPATH(CurDir()) TO pMyDir

CD("F:\Encounter")

WhatFile = GETFILE("TEXT:TXT", "Import File:", "Select", 0, ;
"Please choose the Import File for this report")
IF EMPTY(WhatFile)
*-- FF does not print empty cursors
SELECT 0
CREATE CURSOR MRPWDET_ (Dummy C(10))
RETURN
ELSE
CD pMyDir

 
cd (pMyDir) && use name expression here

also, don't return prematurely, because you're not restoring the directory in that case.
 
OK - After the GetFile() I believe it would have to switch back because the next step in the program is to append the file into a table and the table cannot be found if not in the correct dir.
 
Yes, exactly, move the restoration logic right after GetFile(), e.g.

cd (m.pMyDir) && restore directory
 
But surely you wouldn't do the CD (pMyDir) in the ELSE branch only, or should ELSE simply be ENDIF? Even better do the CD back to the original CurDir before you return, put it directly after the GetFile.

Code:
LOCAL lcCurDir, lcWhatFile

...

lcCurDir = FULLPATH(CurDir())
CD("F:\Encounter")
    
lcWhatFile = GETFILE("TEXT:TXT", "Import File:", "Select", 0, ;
        "Please choose the Import File for this report")

[red]CD (lcCurDir)[/red] && it's best to return to the original CurDir asap.

IF EMPTY(lcWhatFile)
   *-- FF does not print empty cursors
   SELECT 0
   CREATE CURSOR MRPWDET_ (Dummy C(10))
   RETURN
[red]ENDIF[/red] && maybe?
...

Bye, Olaf.
 
I got it... Thank you all for your help! I have only been programming in VFP for 1 year and I learned something totally useful and that I can use over and over.
 
Just my two cents.
Use a parameter for this line

Code:
CD("F:\Encounter")

It is better to extract the value from a table or other easily modified source. Then if the path changes, you only change the value in a table, instead recompiling and redeploying all the app.
Your code may look like this:
Code:
somepath = FunctionToGetFilepath(ParameterToGetFilepath)
CD(SomePath)
 
I've used this subroutine in my code and it works well.
Code:
PARAMETERS tcSearchExt, tcSearchPath
LOCAL lcOldPath, lcNewPath, lcReturnValue
lcOldPath = SYS(5)+SYS(2003)
lcNewPath = IIF(EMPTY(tcSearchPath),lcOldPath,tcSearchPath)
IF lcNewPath <> lcOldPath
   SET DEFAULT TO (lcNewPath)
ENDIF
lcReturnValue = GETFILE(tcSearchExt)  && returns upper case
IF lcNewPath <> lcOldPath
   SET DEFAULT TO (lcOldPath)
ENDIF
RETURN lcReturnValue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top