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

Import same format Programmatically

Status
Not open for further replies.

moremail

Technical User
Aug 23, 2011
10
US
I have searched the forum diligently and am having problems location a code that will perform a simple task.

I have a table already set up. The structure never changes. I want to navigate to a folder, select a csv file and import it into the zapped table. The .csv file structure is always the same also. Can anyone point me in the right direction? Thanks.
 
To navigate to the folder and select the CSV file, use GETFILE().

For example:

Code:
lcFile = GETFILE("CSV")
[code]

To import the file into the table:

[code]
IF NOT EMPTY(lcFile)
  SELECT TheTable
  APPEND FROM (lcFile) TYPE CSV
ENDIF

The reason you need to test for an empty lcFile is that the user might have cancelled out of the GETFILE() dialogue (in which case the function will have returned an empty string).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks so much! That's great and works just as I wanted. Learn something new everyday....

Will
 
My one question left right now is why I can't set default or change directory to:

set default c:\DOCUMENTS AND SETTINGS\WILYNCH\VISUAL PROJECTS\

The simple things sometimes lose focus.
 
You need to put the directory path in quotes - that's because it contains spaces:

Code:
set default "c:\DOCUMENTS AND SETTINGS\WILYNCH\VISUAL PROJECTS\"

But be cautious about hard-coding "documents and settings" - and also the user name. The path might change under different versions of Windows.

If you want to set the default to the directory from which you are launching your application, use JUSTPATH(SYS(16,0)).

mIKE

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top