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

Getfile and Spaces.

Status
Not open for further replies.

shangrilla

Programmer
Nov 21, 2001
360
US
I am using gefiles to get files from a particular directory. Code:

thepath = "'" + ALLTRIM(Tab1.path1) + "'"
If DIRECTORY(tab1.path1) && make sure directory exist first
Chdir &thepath
Endif
getfile('All Files:*.*; *.TXT:txt; *.DOC:doc;*.DAT:dat')

Program looks for file under 'thepath' by default. Users can store any path under this. The problems I am facing is that is the path has spaces in it. Folder names with sapces in them like Program Files will cause problems. How can I avoid these errors? Does getfile has a 254 character size limit for 'thepath'?
 
Let me see if I understand you well.

GetFile() returns file name with full path. You can use File() function to make sure that the user has selected a proper file. I would rewrite your last line and add some code as follows;

cInputFile = getfile('All Files:*.*; *.TXT:txt; *.DOC:doc;*.DAT:dat')

IF FILE(cInputFile)
** No problem, do whatever you want to do
ELSE
** user cancelled or file seleted does not exists
RETURN
ENDIF
 
KKZ:

I take care of checking if the file is of proper format or not later in my code. That is not my concern. Even when I select a proper file from a location that has spaces anyhwere in its path I get an error saying invalid file or path name.

 
Assign the file that is returned from GETFILE to a variable. Then try enclosing the variable in parentheses.

Example:

lc_file_with_spaces = GETFILE(....

MODIFY FILE (lc_file_with_spaces) && OK
MODIFY FILE lc_file_with_spaces && not OK

Hope this helps.

 
Shangrilla:

I would probably get a better picture if you tell me what version you are using for both foxpro and windows.
 
same here. VFP 6.0 AND 2K, but most of our clients use 98.
scooke: I'll try your suggestion here in a bit.
 
lc_file_with_spaces = GETFILE(....

MODIFY FILE '&lc_file_with_spaces' && OK
Attitude is Everything
 
Plus, make sure to make the CHDIR command space-safe:
If DIRECTORY(tab1.path1) && make sure directory exist first
Chdir (thepath) && name expression is space-safe.. Macro replacement &thepath is NOT.
Endif
 
wgcs

correct with name expression. it is the best to use. there are times when it can not. if expression has to be evaluated name expression will not work. when ever in doubt, try it first with name expression. Attitude is Everything
 
shangrilla;

This has worked for me.

m.cdirpath = GETDIR()
*
IF EMPTY(m.cdirpath)
RETURN
ENDIF EMPTY(m.cdirpath)
*
SET DEFA TO EVAL([m.cdirpath])

HTH - Wayne
 
Yes the problem was with chdir(). At places I have to use chdir(&thepath) and other places chdir(thepath).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top