---
rexxpub:
  defaults: rony.yaml
  logo: oorexx
---

<!-- 330_Paths_V03.odp (2026-10-15 09:47) -->

<!-- slide # 1 (2026-10-15 09:47) ----------------------------- ODP slide # 1 -->
. slide cover
# About Storing Files: Where and How?

. subtitle
**Source directory, current directory, home directory, temporary directory …**

. cover-art
. picture img/330_Paths_V03/p01-diagram-7.png

<!-- slide # 2 (2026-10-15 09:47) ----------------------------- ODP slide # 2 -->
# About Locations For Storing Files, 1

. after steps
- 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:`"
            . after
            - 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*)]{.fragment .afterPrevious}

          [`Documents\someFile2.png`                  (*relative path*: relative to *current directory/folder*)]{.fragment .afterPrevious}

        - Unix examples for *absolute* and *relative paths*

          [`/Users/MaryDoe/Documents/someFile1.png`   (*absolute path*)]{.fragment .afterPrevious}

          [`Documents/someFile2.png`                  (*relative path*: relative to *current directory/folder*)]{.fragment .afterPrevious}

<!-- slide # 3 (2026-10-15 09:47) ----------------------------- ODP slide # 3 -->
. slide reference="Cf. rexxref.pdf (2.18. PARSE, 7.4.31. FILESPEC)"
# Source Directory

. after steps
- The directory where the Rexx program is stored
    - Can be retrieved from Rexx using the `PARSE SOURCE` keyword statement

      . after
      ```rexx
      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)]{.fragment .afterPrevious}

          [`/Users/MaryDoe/programs/someProgram.rex`   (absolute path, Unix)]{.fragment .afterPrevious}

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

      [e.g. `FILESPEC('location', pathToRexxProgram)` yields for the above two examples:]{.fragment}

      [`C:\Users\JohnDoe\programs\` (Windows example location)]{.fragment .afterPrevious}

      [`/Users/MaryDoe/programs/`   (Unix example location)]{.fragment .afterPrevious}

<!-- slide # 4 (2026-10-15 09:47) ----------------------------- ODP slide # 4 -->
. slide reference="Cf. rexxref.pdf (7.4.28. DIRECTORY)"
# Current Directory

. steps each=after
- 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
. click
- `directory(optionalNewDir`)-BIF (built-in-function)
    - Returns the full path to the current directory
    - If argument `optionalNewDir` supplied, changes the current directory to it
. click
- Example:

. after
```rexx
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
```

. columns 7 5

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


. next column

. click
Output Unix, assuming current directory is \
`/Users/JohnDoe/temp`:

. end columns

. columns 7 5

. after
```output
C:\Users\MaryDoe\temp
C:\Users\MaryDoe
```


. next column

. after
```output
/Users/JohnDoe/temp
/Users/JohnDoe
```

. end columns

<!-- slide # 5 (2026-10-15 09:47) ----------------------------- ODP slide # 5 -->
. slide reference="Cf. rexxref.pdf (7.4.71. VALUE)"
# Home Directory

. after
- The directory (folder) where all files and directories/folders of a user reside
    . after
    - User usually has all permissions for all directories/folders and files therein
. click
- Operating system defines an environment variable that contains the path
    . after
    - Environment variable (Windows): "`USERPROFILE`"
    . after
    - Environment variable (UNIX):   "`HOME`"
. click
- Use the `value()`-BIF (built-in-function) to retrieve the environment variable's value, e.g.
    . after
    - Example Windows:
      ```rexx
      homeDir=value('USERPROFILE', ,'ENVIRONMENT') -- maybe: "C:\Users\JohnDoe"
      ```
    . after
    - Example Unix:
      ```rexx
      homeDir=value('HOME', ,'ENVIRONMENT')        -- maybe: "/Users/MaryDoe"
      ```

<!-- slide # 6 (2026-10-15 09:47) ----------------------------- ODP slide # 6 -->
. slide reference="Cf. rexxref.pdf (7.4.71. VALUE)"
# Temporary Directory

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

      . after
      ```rexx
      tempDir=value('TEMP',,'ENVIRONMENT')   -- maybe "C:\Users\JohnDoe\AppData\Local\Temp"
      ```

    - MacOS: defined with the environment variable "`TMPDIR`"

      . after
      ```rexx
      tempDir=value('TMPDIR',,'ENVIRONMENT') -- maybe "/var/folders/x9/gyg5hmn/T/"
      ```

    - Unix: usually the directory "`/tmp`"

<!-- slide # 7 (2026-10-15 09:47) ----------------------------- ODP slide # 7 -->
. slide logo=bsf4oorexx
# Using Java to Fetch these Directories

. after
- Java's `java.util.System`  class manages the properties for the system
    . click
    - The following properties are set according to the user's operating system

. steps each=after level=2
| Directory | Name of System Property|
|---|---|
| Current directory   | "`user.dir`" |
| Home directory      | "`user.home`" |
| Temporary directory | "`java.io.tmpdir`" |

. click level=2
```rexx
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
```

. click level=2
Possible output (Windows) assuming current directory is  C:\\Program `Files\ooRexx`:

. after level=2
```output
User name            : JohnDoe
User's home directory: C:\Users\JohnDoe
Current directory    : C:\Program Files\ooRexx
Temp directory       : C:\Users\JohnDoe\AppData\Local\Temp\
```

<!-- slide # 8 (2026-10-15 09:47) ------------ business card (not in the ODP) -->
. slide card logo=none
# Contact