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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SET PATH or SET DEFAULT TO

Status
Not open for further replies.

KDavie

Programmer
Feb 10, 2004
441
US
I've had ongoing problems with SET PATH and SET DEFAULT since I've began to learn VFP earlier this year. I am hoping you gurus can help me clarify between the two and perhaps figure out why I can't get them to work as expected.

In the beginning of my main program I issue a SET DEFAULT to the directory where that database resides. This works fine. Throughout my application there are points where I use GETFILE() to get the path of a file, and SET PATH to set the path to that file's respective path (I parse the path from the string without the filename) so I can use it. I can never seem to get this to work. It always tells me the file can not be found. If I issue a CURDIR() to see what the current directory is, it never changes from the default directory.

My question is:

How can I tell FoxPro to look into a specific directory for a file.

Any help is appreciated.

-Kevin
 
am really not an expert but i can share this with you. generally, i create several subfolders under the folder where my app resides. then in my main program, i tell my app to look for whatever file needed in any of the subfolders under the directory where my app resides, like so:
Code:
FldrMain = justpath(sys(16, 0))  [COLOR=green]&& the main directory where my app is run[/color]
SET PATH TO (FldrMain + [\Graphics]), ;
     (FldrMain + [\DBData]), ;
     (FldrMain + [\Others]
this way, my app can look for whatever file it needs under the other 3 subfolders as long as both files and folders exist. this also helps resolve the portability problem of my apps.

hope this helps. peace! [peace]


kilroy [trooper]
philippines

"Illegitimis non carborundum!"
 
my apologies sir but my code should look like this:
Code:
FldrMain = justpath(sys(16, 0))  [COLOR=green]&& the main directory where my app is run[/color]
SET PATH TO (FldrMain + [\Graphics, ] + ;
     FldrMain + [\DBData, ] + ;
     FldrMain + [\Others])
peace! [peace]

kilroy [trooper]
philippines

"Illegitimis non carborundum!"
 
kilroy,

Thanks for the reply. I will try your solution.

-Kevin

 
Kevin,

How are you parsing the path name from the result of GETFILE()? Are you using JUSTPATH()? Are you confident that the parsing is giving the correct result?

Perhaps you could post your code.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Kevin,

I too have had similar problems in the past. What I now like to do is create a custom application object that contains protected properties and accessor methods for typical things like the current path, database path and any other global/public value that I need. This gives me one place to look for these values. An added benefit is that I now don't have to worry about inadvertantly modifying the values with some sloppy code.

Ralph
 
Hi Kevin.

Throughout my application there are points where I use GETFILE() to get the path of a file, and SET PATH to set the path to that file's respective path (I parse the path from the string without the filename) so I can use it. I can never seem to get this to work

I do not understand why you need to set the PATh so that you can use the file. GETFILE() returns a fully qualified file name complete with path, so you know exactly where it is and should be able to access it without modifying the path at all.

Or is there something else that I am missing here?



Marcia G. Akins
 
Thanks for all the reply's.

Mike,

I am parsing the string with the RAT and LEFT functions. Here is the code:

PROCEDURE btnGetFile.Click
lcPath = GETFILE()
lnCharCount = RAT("\",lcPath) - 1
lcFileName = LEFT(lcPath,lnCharCount)
SET PATH TO lcFileNAme
IMPORT FROM newwork TYPE xls
ENDPROC

I have tested the value of lcFileName and it is correct.


Marcia,

Originally I tried something like this:

lcPath = GETFILE()
IMPORT FROM &lcPath TYPE xls


But couldn't get it to work either, so ended up trying to do it this way.


Thank you all for your help.

-Kevin
 
Kevin,

First, I suggest you use JUSTPATH() to parse out the path name. But in any case, the code you posted won't work, because of this line:

SET PATH TO lcFileNAme

You need to either put lcFileName in parentheses or precede it with & to make it work (but the & is no good of the path contains spaces).

Mike

Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Thanks Mike,

I changed the parsing part to JUSTPATH() after your first post. I will try putting lcFileName in parentheses.

Thanks again

-Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top