About Storing Files: Where and How?

Source directory, current directory, home directory, temporary directory …

330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)

About Locations For Storing Files, 1

  • About directories (synonym: folders)
    • Can be nested (directory/folder in a directory/folder …)
    • Root directory has the symbol "/" (Unix) or "\" (Windows)
      • Windows has the notion of a drive, an alphabetic letter followed by a colon, e.g. "C:"
        • A drive may be prepended to the directory, e.g. to the root directory: "C:\"
    • A PATH is the sequence of directories (folders) to traverse to arrive at the storage location of a file
      • Each directory (folder) gets separated with the letter "/" (Unix) or "\" (Windows)

      • Windows examples for absolute (starts with the root directory/folder) and relative paths

        C:\Users\JohnDoe\Documents\someFile1.png (absolute path)

        Documents\someFile2.png (relative path: relative to current directory/folder)

      • Unix examples for absolute and relative paths

        /Users/MaryDoe/Documents/someFile1.png (absolute path)

        Documents/someFile2.png (relative path: relative to current directory/folder)

330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)

Source Directory

  • The directory where the Rexx program is stored
    • Can be retrieved from Rexx using the PARSE SOURCE keyword statement

      PARSE SOURCE opsys invocationType pathToRexxProgram
      • opsys refers to the operating system, e.g. "Windows", "Darwin" (Apple), "Linux", …

      • invocationType is one of "COMMAND", "FUNCTION", "SUBROUTINE", "METHOD", "REQUIRES"

      • pathToRexxProgram is the fully qualified path to the Rexx program, e.g.

        C:\Users\JohnDoe\programs\someProgram.rex (absolute path, Windows)

        /Users/MaryDoe/programs/someProgram.rex (absolute path, Unix)

    • FILESPEC()-BIF (built-in-function) allows to retrieve different parts of a path

      e.g. FILESPEC('location', pathToRexxProgram) yields for the above two examples:

      C:\Users\JohnDoe\programs\ (Windows example location)

      /Users/MaryDoe/programs/ (Unix example location)

330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)

Current Directory

  • The directory (folder) where the Rexx program executes
    • Used for looking up additional programs and files without a path
    • Can be changed arbitrarily while the program executes
  • directory(optionalNewDir)-BIF (built-in-function)
    • Returns the full path to the current directory
    • If argument optionalNewDir supplied, changes the current directory to it
  • Example:
say directory()        -- returns path to current directory
oldDir=directory("..") -- changes to parent directory/folder ("."=current, ".."=parent directory/folder)
say directory()        -- returns path to current directory

Output Windows, assuming current directory is
C:\Users\MaryDoe\temp:

Output Unix, assuming current directory is
/Users/JohnDoe/temp:

C:\Users\MaryDoe\temp
C:\Users\MaryDoe
/Users/JohnDoe/temp
/Users/JohnDoe
330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)

Home Directory

  • The directory (folder) where all files and directories/folders of a user reside
    • User usually has all permissions for all directories/folders and files therein
  • Operating system defines an environment variable that contains the path
    • Environment variable (Windows): "USERPROFILE"
    • Environment variable (UNIX): "HOME"
  • Use the value()-BIF (built-in-function) to retrieve the environment variable's value, e.g.
    • Example Windows:
      homeDir=value('USERPROFILE', ,'ENVIRONMENT') -- maybe: "C:\Users\JohnDoe"
    • Example Unix:
      homeDir=value('HOME', ,'ENVIRONMENT')        -- maybe: "/Users/MaryDoe"
330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)

Temporary Directory

  • Every operating system defines a directory for temporary files
    • Rights for everyone to read and write files
      • May be emptied by the operating system, e.g. during boot process
      • Beware of storing sensitive data there!
  • Temporary directories on different operating systems
    • Windows: defined with the environment variable "TMP" or "TEMP"

      tempDir=value('TEMP',,'ENVIRONMENT')   -- maybe "C:\Users\JohnDoe\AppData\Local\Temp"
    • MacOS: defined with the environment variable "TMPDIR"

      tempDir=value('TMPDIR',,'ENVIRONMENT') -- maybe "/var/folders/x9/gyg5hmn/T/"
    • Unix: usually the directory "/tmp"

330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)

Using Java to Fetch these Directories

  • Java's java.util.System class manages the properties for the system
    • The following properties are set according to the user's operating system
Directory Name of System Property
Current directory "user.dir"
Home directory "user.home"
Temporary directory "java.io.tmpdir"
say "User name            :" .java.lang.System~getProperty("user.name")
say "User's home directory:" .java.lang.System~getProperty("user.home")
say "Current directory    :" .java.lang.System~getProperty("user.dir")
say "Temp directory       :" .java.lang.System~getProperty("java.io.tmpdir")

::requires BSF.CLS -- get ooRexx-Java bridge

Possible output (Windows) assuming current directory is C:\Program Files\ooRexx:

User name            : JohnDoe
User's home directory: C:\Users\JohnDoe
Current directory    : C:\Program Files\ooRexx
Temp directory       : C:\Users\JohnDoe\AppData\Local\Temp\
330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)

Contact

WU

Prof. Mag. Dr. Rony G. Flatscher

Welthandelsplatz 1

1020 Wien/Vienna

Austria/Europe


www: www.wu.ac.at

330_Paths_V03.md (2026-10-18 · 19:11:20)
v1.00 · 2026-10-02 (created 2026-11-12 23:14:43, md2slides v387)