All Manuals > LispWorks® User Guide and Reference Manual > 27 LispWorks' Operating Environment

27.15 Special locations in the file system

This section describes interfaces allowing you to identify and access various special locations in the file system.

27.15.1 The home directory

This section describes the implementation of the Common Lisp function cl:user-homedir-pathname.

On Unix-based systems, the home directory is looked up using the C function getpwuid.

On Microsoft Windows systems, cl:user-homedir-pathname uses the environment to construct its result. It uses the values of the environment variables HOMEDRIVE and HOMEPATH, if both are defined. If at least one of environment variables HOMEDRIVE and HOMEPATH is not defined, then a pathname #P"C:/users/login-name" is returned. These environment variables should be correctly set before LispWorks starts. However it is possible to change the values in Lisp using setf with environment-variable.

On Android cl:user-homedir-pathname returns the result of calling "android.os.Environment.getExternalStoragePublicDirectory" with the value of android.os.Environment.DIRECTORY_DOCUMENTS.

27.15.2 Special Folders

On Microsoft Windows, macOS and Android there are various special folders used for application data and user data. Here are some examples of the folder for application data which is shared between all users.

Windows 10, Windows 8, Windows 7 and Windows Vista

C:\ProgramData

Windows XP (now unsupported)

C:\Documents and Settings\All Users.WINDOWS\Application Data

macOS

/Library/Application Support

Android

The result of calling getExternalFilesDir on the application context with null.

The locations and folder names can differ between versions of the operating system, therefore it is useful to have a system-independent way to get the path at run time. The function get-folder-path can be used to retrieve the path to special folders. Directory pathnames corresponding to each of the examples above can be obtained by calling:

(sys:get-folder-path :common-appdata)

Here is another example of differences between operating systems. On Windows 7 and Windows Vista:

(sys:get-folder-path :my-documents)
=>
#P"C:/Users/dubya/Documents/"

On macOS:

(sys:get-folder-path :my-documents)
=>
#P"/u/ldisk/dubya/Documents/"

See get-folder-path for more details.

On Microsoft Windows there is a profile folder for each user. You can find the profile path for the current user with the function get-user-profile-directory.

27.15.3 Temporary files

A "temp file" is a file in the "temp directory" which is guaranteed to be new. Its name contains a random element.

Create a temp file by calling either of the functions open-temp-file and create-temp-file. For example:

On Microsoft Windows:

(create-temp-file :prefix "LW")
=>
#P"C:/DOCUME~1/dubya/LOCALS~1/Temp/LW383vwVfZN.tmp"

On Linux:

(create-temp-file :prefix "LW")
=>
#P"/tmp/LW1adokNa.tmp"

The function set-temp-directory allows you to set the "temp directory", that is the default directory used for temp files.


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:24