Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Mar 11, 2008


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Access to System Directories from LabVIEW

2 ratings | 5.00 out of 5
Print

Overview

This document is the first proposal for the changes regarding access to system directories that will occur in a future version of LabVIEW. Our goal is to work with the LabVIEW community to provide guidelines on proper usage of system directories. This will provide a general overview of the changes. In the future, we plan to provide many more details.

This proposal originates from a LabVIEW Feature Brainstorming discussion post titled System directory access and LabVIEW directory changes.

These changes will not occur in LabVIEW until 2009 or later.

Also refer to Changes in the LabVIEW Directory for information on other directory-related changes that will occur in a future version of LabVIEW.

  The Problem

"Cross-platform applications... must not use hard-coded paths." 

Cross-platform applications with a dispersed directory structure must not use hard-coded paths. We need to account not only for differences between platforms, but differences between versions of the same platform -- for example, differences between Microsoft Windows XP and Microsoft Windows Vista. 

We must provide an API to allow users to create applications free of hard-coded system paths that might change between different systems. For example, the Program Files directory differs between XP, Vista32, and Vista64 and the User Documents directories differ between XP and Vista, as shown below.

Example

The user's documents directory on Windows 2000 and XP:

     C:\Documents and Settings\<Username>\My Documents\

The user's documents directory on Windows Vista:

     C:\Users\<Username>\Documents\

Current System Directory Access

LabVIEW currently provides path constants to a few application and system directories. These include:

  • Temporary directory is currently used to save various LabVIEW application files and is not appropriate for most end-user applications
  • Default Data directory is a version-independent  LabVIEW directory under the user's Documents directory
  • Default directory is often not clear on which disk location is associated with the path constant.

These locations are insufficient for most end-users to create applications that use a dispersed directory structure.

  The Solution

"LabVIEW will help customers succeed..." 

We will introduce a new Get System Directory VI that provides access to key root directories available on all supported platforms. Below, the VI gets the user's home directory. The expanded ring listing of available directory types also is shown. 

A directory listed above might not exist, for example, if a user deletes that special directory. The Create Directory input allows the user to create the directory if it does not exist. You also can use this VI to check if the directory exists.   

In addition, the Installer Builder will expand its set of special directories to include, for example, Public Documents and Public Application Data.

Example Usage

Below, the Get System Directory VI accesses files that are relative to a special system directory. 

 

Open an application readme file in a browser

Write a log file to the User Application Data directory

  Directory Types

The following table lists the proposed Directory Types available in Get System Directory.vi along with the returned paths on the different supported operating systems.

Directory Type Directory path returned for each operating system
User Home
Windows XP: C:\Documents and Settings\<user>
Windows Vista: C:\Users\<user>
Mac OSX: /Users/<user>
Linux: /home/<user>
User Desktop
Windows XP: C:\Documents and Settings\<user>\Desktop
Windows Vista: C:\Users\<user>\Desktop
Mac OSX: /Users/<user>/Desktop
Linux: /home/<user>/Desktop
User Documents
Windows XP: C:\Documents and Settings\<user>\My Documents
Windows Vista: C:\Users\<user>\Documents
Mac OSX: /Users/<user>/Documents
Linux: /home/<user>
User Application Data
Windows XP: C:\Documents and Settings\<user>\Local Settings\Application Data
Windows Vista: C:\Users\<user>\AppData\Local
Mac OSX: /Users/<user>/Library/Application Support
Linux: /home/<user>
User Preferences
Windows XP: C:\Documents and Settings\<user>\Local Settings\Application Data
Windows Vista: C:\Users\<user>\AppData\Local
Mac OSX: /Users/<user>/Library/Preferences
Linux: /home/<user>
Public Documents
Windows XP: C:\Documents and Settings \All Users\Documents
Windows Vista: C:\Users\Public\Documents
Mac OSX: /Library/Application Support
Linux: /usr/local/
Public Application Data
Windows XP: C:\Documents and Settings\ All Users\Application Data
Windows Vista: C:\ProgramData
Mac OSX: /Library/Application Support
Linux: /usr/local/
Public Preferences
Windows XP: C:\Documents and Settings\ All Users\Application Data
Windows Vista: C:\ProgramData
Mac OSX: /Library/Preferences
Linux: /etc
System Libraries
Windows XP: C:\Windows\System32
Windows Vista: C:\Windows\System32
Mac OSX: /Library/Frameworks
Linux: /usr/lib
Application Files
Windows XP: C:\Program Files
Windows Vista: C:\Program Files
Mac OSX: /Applications
Linux: /usr/local/
Volume Root
Windows XP: C:\
Windows Vista: C:\
Mac OSX: /
Linux: /
Temp
Windows XP: C:\Documents and Settings \<user>\Local Settings\Temp
Windows Vista: C:\Users\<user>\AppData \Local\Temp
Mac OSX: /private/tmp/folders.501 /TemporaryItems
Linux: /tmp

 

  Comments on API Decisions

Names:

Since directory naming conventions vary across platforms, we chose platform-neutral terminology.

Paths:

LabVIEW will utilize the following system paths.

Windows: operating system API determines path, specifically SHGetFolderPath().
Mac OS: operating system API determines path, specifically FSFindFolder().  
Linux: Users rely on conventions for directory creations and use (no standard API).

Set of directories:

We provide access to the standard directories that are most useful to LabVIEW applications and do not cause cross-platform problems.  

Installer Builder

The Get System Directory VI allows you to access system directories at runtime.  In addition, the Installer Builder will expand its set of special directories to include, for example, Public Documents and Public Application Data, thus allowing you access to the same set of directories at install time.

Forum Questions

"LabVIEW wants your feedback..." 

  1. Do you agree with that we have the right set of directories in the Directory Type list?  If not, what should be added or removed? [forum link]
  2. Do you agree with our cross-platform names (User Documents, Public Preferences, etc.) and their associated disk locations? [forum link]
  3. Besides Get System Directory VI and more entries in Installer Builder, what other features are needed to create applications that disperse files to appropriate special operating system directories? [forum link]
  4. Other comments/questions about the Get System Directory VI? [forum link]

 

2 ratings | 5.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).