FoxPro JustStem() function

The VFP JustStem() function returns the stem of a file name, the name with the period and extension removed. It can accept a filename with or without a path:

JustStem ("C:\Microsoft Visual FoxPro 9\vfp9.exe")

would return:

"vfp9"

The JustStem() function can accept a folder name instead of a filename but it is similar to JustPath() in the way that its behaviour changes depending on whether or not the folder name ends in a backslash.

JustStem() is useful when you are copying files or exporting data. If you are sending data from a table to an Excel file then you can use this function to build the name of an xls file which matches the table name:

*-- Get the name of the table behind the current alias
*-- then extract its stem.
lcTableName = Dbf()
lcStem = JustStem(lcTableName)

*-- Now build the name of the xls and export the data.
lcXlsName = lcStem + ".xls"
Copy To &lcXlsName Type Xls

This is a simple example which just dumps the xls file into the current folder. A practical example would read the name of the export folder from a table or ask the user where they wanted to store the exported data.

VBA equivalent

Microsoft Access does not have equivalents to these FoxPro file name commands so I wrote this library Visual Basic functions to do give me the same facilities in VBA.

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

FoxPro Functions

FoxPro has always had functions like FREAD and FWRITE to read and write files at a low level. They can handle files which defeat the STRTOFILE and FILETOSTR functions.

Read More

FoxPro DefaultExt function

FoxPro functions to manipulate names of files and folders

Read More

FoxPro ForceExt function

FoxPro functions to manipulate names of files and folders

Read More

FoxPro ForcePath function

FoxPro functions to manipulate names of files and folders

Read More

FoxPro JustExt function

FoxPro functions to manipulate names of files and folders

Read More