Saving files to the Windows desktop

Many applications produce output in the form of a disk file. This may be a simple text file listing an audit trail; a Word document as a personalised letter; or an Excel spreadsheet as an alternative to a printed report.

If these files need to be kept for any length of time or if there are many different types of file then they are best kept in a structure of separate folders. If however the files are produced rarely and will be be printed or despatched immediately then the desktop may be the best place to put them.

This sounds like an unstructured way of working but it does have a number of advantages - especially for unskilled or occasional users:

  • The files are obviously 'there' and the user will know that the application has produced the output.
  • The user can't lose the files or forget the path to the folder.
  • Files can't accumulate because the user can see the old files and will be able to delete them

Where is the desktop?

The desktop is nothing more than a folder. It has different names in different versions of Windows and there may be several different copies of it, one for each user. On this machine my desktop is stored as:

c:\Documents and Settings\gfranklin\Desktop

You may be tempted to build this string for yourself but there is no guarantee that the desktop folder will always have a path of this form. A safer method is to ask Windows for the path.

Finding the desktop

Use the Windows Scripting Host(WSH) to get this information. The SpecialFolders method will return the path:

loShell = CreateObject ('WScript.Shell')
lcDesktop = loShell.SpecialFolders('desktop')

Once you have the path you can very easily write your file to this folder with the STRTOFILE command:

lcFileName = InputBox ('Enter a file name')
StrToFile ('Test', lcDeskTop + '\' + lcFileName)
MessageBox (lcFilename + ' saved to Desktop.')

The MessageBox is just there to reassure the user because the new file may be hidden on the desktop behind the application that's running.

More tips from Alvechurch Data

More tips from Alvechurch Data

FoxPro TextMerge

Using TextMerge to export text, html or xml files from FoxPro.

Read More

Exporting from FoxPro to text files.

Export FoxPro data to comma separated and other types of delimited text files

Read More

FoxPro TextMerge example

TextMerge code to export FoxPro data to html.

Read More