vLife Systems

Quality Through Design

  Home   |   Projects > AppDirs   |   Articles   |   Archive   |  

AppDirs A Tcl Module to Simplify Cross-platform Application File Locations

An application that is installed on a variety of platforms will use different locations on each platform to access files. This module aims to provide access to these locations through a common interface. For each operating system the module aims to use an appropriate standard for the locations, for example on Linux the XDG Base Directory Specification is used and on Microsoft Windows or Darwin/Mac OS X the most common locations for each version of the operating system is used.

Module Usage

First create an instance of the AppDirs class by instantiating it with a brand and applicationName. The brand may be ignored depending on the platform that is being used. You can then call the methods on this instance as follows:
package require AppDirs

set myAppDirs [AppDirs new myBrand myApp]

# Return location of user-specific data files
puts "data home: [$myAppDirs dataHome]"

# Return location of user-specific configuration files
puts "config home: [$myAppDirs configHome]"

# Return a list of locations for system-wide configuration files in preference order
puts "data dirs: [$myAppDirs dataDirs]"

# Return a list of locations for system-wide data files in preference order
puts "config dirs: [$myAppDirs configDirs]"

Default Directories

To list the default directories for various platforms and to see the directories being used for the current system run:
$ tclsh bin/listdirs.tcl

Installation

To install the module you can use the installmodule.tcl script or if you want to manually copy the file AppDirs-*.tm to a specific location that Tcl expects to find modules. This would typically be something like:
/usr/share/tcltk/tcl8.5/tcl8/
To find out what directories are searched for modules, start tclsh and enter:
foreach dir [split [::tcl::tm::path list]] {puts $dir}
or from the command line:
$ echo "foreach dir [split [::tcl::tm::path list]] {puts \$dir}" | tclsh

Find out More

To find out more have a look at the following articles:

Downloads

AppDirs v0.2

Requirements

Contributions

If you want to improve this program make a pull request to the repo on github. Please put any pull requests in a separate branch to ease integration and add a test to prove that it works. If you find a bug, please report it at the AppDirs_tcl project's issues tracker also on github.

Licence

Copyright (C) 2013-2015, Lawrence Woodman lwoodman@vlifesystems.com
This software is licensed under an MIT Licence. Please see the file, LICENCE.md, for details.