# 14.15 Deprecation
Returns path with “normalized” case characters. For Unix and Mac OS paths, this procedure always returns the input path, because filesystems for these platforms can be case-sensitive. For Windows paths, if path does not start with \\\\?\\, the resulting string uses only lowercase letters, based on the current locale. In addition, for Windows paths when the path does not start with \\\\?\\, all /s are converted to \\s, and trailing spaces and .s are removed.
The path argument can be a path for any platform, but beware that local-sensitive decoding and conversion of the path may be different on the current platform than for the path’s platform.
This procedure does not access the filesystem.
> ```
(split-path path)    →    (or/c path-for-some-system? 'relative #f)
(or/c path-for-some-system? 'up 'same)
boolean?
  path : (or/c path-string? path-for-some-system?)```
Deconstructs path into a smaller path and an immediate directory or file name. Three values are returned:
-   base is either
    -   a path,
    -   'relative if path is an immediate relative directory or filename, or
    -   #f if path is a root directory.
-
    name is either
    -   a directory-name path,
    -   a filename,
    -   'up if the last part of path specifies the parent directory of the preceding path (e.g., .. on Unix), or
    -   'same if the last part of path specifies the same directory as the preceding path (e.g., . on Unix).


# 14.15 Deprecation
-   must-be-dir? is #t if path explicitly specifies a directory (e.g., with a trailing separator), #f otherwise. Note that must-be-dir? does not specify whether name is actually a directory or not, but whether path syntactically specifies a directory.
Compared to path, redundant separators (if any) are removed in the result base and name. If base is #f, then name cannot be 'up or 'same. The path argument can be a path for any platform, and resulting paths for the same platform.
This procedure does not access the filesystem.
See [Unix and Mac OS Paths](unixpaths.html) and [Windows Paths](windowspaths.html) for more information on splitting paths.
> ```
(explode-path path)
  →  (listof (or/c path-for-some-system? 'up 'same))
  path : (or/c path-string? path-for-some-system?)


# 14.15 Deprecation
```
Returns the list of path elements that constitute path. If path is simplified in the sense of simple-form-path, then the result is always a list of paths, and the first element of the list is a root.

The explode-path function computes its result in time proportional to the length of path (unlike a loop that uses split-path, which must allocate intermediate paths).

> ```
(path-replace-extension path ext)   →   path-for-some-system?
  path : (or/c path-string? path-for-some-system?)
  ext : (or/c string? bytes?)```

Returns a path that is the same as path, except that the extension for the last element of the path (including the extension separator) is changed to ext. If the last element of path has no extension, then ext is added to the path.

An extension is defined as a . that is not at the start of the path element followed by any number of non-. characters/bytes at the end of the [path element](More_Path_Utilities.html#%28tech._path._element%29), as long as the path element is not a directory indicator like "..".

The path argument can be a path for any platform, and the result is for the same platform. If path represents a root, the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised. The given ext typically starts with ., but it is not required to start with an extension separator.

Examples:

> ```racket
> > ( path-replace-extension "x/y.ss" #".rkt" )
> #<path:x/y.rkt>
> > ( path-replace-extension "x/y.ss" #"" )
> #<path:x/y>
> > ( path-replace-extension "x/y" #".rkt" )
> #<path:x/y.rkt>
> > ( path-replace-extension "x/y.tar.gz" #".rkt" )
> #<path:x/y.tar.rkt>
> > ( path-replace-extension "x/.racketrc" #".rkt" )
> #<path:x/.racketrc.rkt>
> ```

Added in version 6.5.0.3 of package base.

> ```
(path-add-extension path ext [sep) → path-for-some-system?
  path : (or/c path-string? path-for-some-system?)
  ext : (or/c string? bytes?)
  sep : (or/c string? bytes?) = #"_"
```


# 14.15 Deprecation
Similar to path-replace-extension, but any existing extension on path is preserved by replacing the . before the extension with sep, and then the ext is added to the end.
Examples:
> ```racket
> > ( path-add-extension "x/y.ss" #".rkt" )
> #<path:x/y_ss.rkt>
> > ( path-add-extension "x/y" #".rkt" )
> #<path:x/y.rkt>
> > ( path-add-extension "x/y.tar.gz" #".rkt" )
> #<path:x/y.tar_gz.rkt>
> > ( path-add-extension "x/y.tar.gz" #".rkt" #"." )
> #<path:x/y.tar.gz.rkt>
> > ( path-add-extension "x/.racketrc" #".rkt" )
> #<path:x/.racketrc.rkt>
> ```
Added in version 6.5.0.3 of package base.
Changed in version 6.8.0.2: Added the sep optional argument.
> ```
(path-replace-suffix path ext)   →   path-for-some-system?
  path : (or/c path-string? path-for-some-system?)
  ext : (or/c string? bytes?)```
> NOTE: This function is deprecated; use [path-replace-extension](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-replace-extension%29%29), instead.
Like [path-replace-extension](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-replace-extension%29%29), but treats a leading . in a path element as an extension separator.
> ```
(path-add-suffix path ext)  →  path-for-some-system?
  path : (or/c path-string? path-for-some-system?)
  ext : (or/c string? bytes?)


# 14.15 Deprecation
```
> NOTE: This function is deprecated; use path-add-extension, instead.

Like path-add-extension, but treats a leading . in a path element as an extension separator.

> ```
(reroot-path path root-path)   →   path-for-some-system?
  path : (or/c path-string? path-for-some-system?)
  root-path : (or/c path-string? path-for-some-system?)```

Produces a path that extends root-path based on the complete form of path.

If path is not already [complete](#%28tech._complete%29), is it completed via [path->complete-path](#%28def._%28%28quote._~23~25kernel%29._path-~3ecomplete-path%29%29), in which case path must be a path for the current platform. The path argument is also [cleanse](pathutils.html#%28tech._cleanse%29)d and case-normalized via [normal-case-path](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._normal-case-path%29%29). The path is then appended to root-path; in the case of Windows paths, a root letter drive becomes a letter path element, while a root UNC path is prefixed with "UNC" as a path element and the machine and volume names become path elements.

Examples:

> ```racket
> > ( reroot-path ( bytes->path #"/home/caprica/baltar" ' unix ) ( bytes->path #"/earth" ' unix ) )
> #<path:/earth/home/caprica/baltar>
> > ( reroot-path ( bytes->path #"c:\\usr\\adama" ' windows ) ( bytes->path #"\\\\earth\\africa\\" ' windows ) )
> #<windows-path:\\earth\africa\c\usr\adama>
> > ( reroot-path ( bytes->path #"\\\\galactica\\cac\\adama" ' windows ) ( bytes->path #"s:\\earth\\africa\\" ' windows ) )
> #<windows-path:s:\earth\africa\UNC\galactica\cac\adama>
> ```

------------------------------------------------------------------------

# 15.1.2 More Path Utilities

#### 15.1.2 More Path Utilities

|                                                                                |                                                                                |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/path]()) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |

The bindings documented in this section are provided by the [racket/path]() and [racket](index.html) libraries, but not [racket/base](index.html).

> ```
(file-name-from-path path)  →  (or/c path-for-some-system? #f)
  path : (or/c path-string? path-for-some-system?)
```


# 14.15 Deprecation
Returns the last element of path. If path is syntactically a directory path (see split-path), then the result is #f.
> ```
(path-get-extension path)   →   (or/c bytes? #f)
  path : (or/c path-string? path-for-some-system?)```
Returns a byte string that is the extension part of the filename in path, including the . separator. If the path has no extension, #f is returned.
See [path-replace-extension](Manipulating_Paths.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-replace-extension%29%29) for the definition of a filename extension.
Examples:
> ```racket
> > ( path-get-extension "x/y.rkt" )
> #".rkt"
> > ( path-get-extension "x/y" )
> #f
> > ( path-get-extension "x/y.tar.gz" )
> #".gz"
> > ( path-get-extension "x/.racketrc" )
> #f
> ```
Added in version 6.5.0.3 of package base.
> ```
(path-has-extension? path ext)  →  boolean?
  path : (or/c path-string? path-for-some-system?)
  ext : (or/c bytes? string?)


# 14.15 Deprecation
```
Determines whether the last element of path ends with ext but is not exactly the same as ext.

If ext is a byte string with the shape of an extension (i.e., starting with . and not including another .), this check is equivalent to checking whether (path-get-extension path) produces ext.

Examples:

> ```racket
> > ( path-has-extension? "x/y.rkt" #".rkt" )
> #t
> > ( path-has-extension? "x/y.ss" #".rkt" )
> #f
> > ( path-has-extension? "x/y" #".rkt" )
> #f
> > ( path-has-extension? "x/.racketrc" #".racketrc" )
> #f
> > ( path-has-extension? "x/compiled/y_rkt.zo" #"_rkt.zo" )
> #t
> ```

Added in version 6.5.0.3 of package base.

> ```
(filename-extension path)   →   (or/c bytes? #f)
  path : (or/c path-string? path-for-some-system?)```

> NOTE: This function is deprecated; use [path-get-extension](#%28def._%28%28lib._racket%2Fpath..rkt%29._path-get-extension%29%29), instead.

Returns a byte string that is the extension part of the filename in path without the . separator. If path is syntactically a directory (see [split-path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._split-path%29%29)) or if the path has no extension, #f is returned.

> ```
(find-relative-path base
    path
   [ #:more-than-root? more-than-root?
    #:more-than-same? more-than-same?
    #:normalize-case? normalize-case?)

  →  (or/c path-for-some-system? path-string?)
  base : (or/c path-string? path-for-some-system?)
  path : (or/c path-string?  path-for-some-system?)
  more-than-root? : any/c = #f
  more-than-same? : any/c = #t
  normalize-case? : any/c = #t
```


# 14.15 Deprecation
(current-directory)	→
(-> and/c path-string? complete-path?)```
> > > For most purposes, [simple-form-path](#%28def._%28%28lib._racket%2Fpath..rkt%29._simple-form-path%29%29) is the preferred mechanism to normalize a path, because it works for paths that include non-existent directory components, and it avoids unnecessarily expanding soft links.
Returns a complete version of path by making the path complete, expanding the complete path, and resolving all soft links (which requires consulting the filesystem). If path is relative, then wrt is used as the base path.
Letter case is not normalized by [normalize-path](#%28def._%28%28lib._racket%2Fpath..rkt%29._normalize-path%29%29). For this and other reasons, such as whether the path is syntactically a directory, the result of [normalize-path](#%28def._%28%28lib._racket%2Fpath..rkt%29._normalize-path%29%29) is not suitable for comparisons that determine whether two paths refer to the same file or directory (i.e., the comparison may produce false negatives).
An error is signaled by [normalize-path](#%28def._%28%28lib._racket%2Fpath..rkt%29._normalize-path%29%29) if the input path contains an embedded path for a non-existent directory, or if an infinite cycle of soft links is detected.
Example:
> ```racket
> > ( equal? ( current-directory ) ( normalize-path "." ) )
> #t
> ```
> ```
(path-element? path)  →  boolean?
  path : any/c


# 14.15 Deprecation
```
Returns #t if path is a path element: a path value for some platform (see path-for-some-system?) such that split-path applied to path would return 'relative as its first result and a path as its second result. Otherwise, the result is #f.

> ```
(path-only path)   →   (or/c #f path-for-some-system?)
  path : (or/c path-string? path-for-some-system?)```

Returns path without its final path element in the case that path is not syntactically a directory; if path has only a single, non-directory path element, #f is returned. If path is syntactically a directory, then path is returned unchanged (but as a path, if it was a string).

Examples:

> ```racket
> > ( path-only ( build-path "a" "b" ) )
> #<path:a/>
> > ( path-only ( build-path "a" ) )
> #f
> > ( path-only ( path->directory-path ( build-path "a" ) ) )
> #<path:a/>
> > ( path-only ( build-path ' up ' up ) )
> #<path:../..>
> ```

> ```
(simple-form-path path)  →  path?
  path : path-string?
```
Returns (simplify-path (path  →  complete-path path)), which ensures that the result is a complete path containing no up- or same-directory indicators.
> ```
(some-system-path  →  string path)   →   string?
  path : path-for-some-system?```
Converts path to a string using a UTF-8 encoding of the path’s bytes.
Use this function when working with paths for a different system (whose encoding of pathnames might be unrelated to the current locale’s encoding) and when starting and ending with strings.
> ```


# 14.15 Deprecation
(string  →  some-system-path str kind)  →  path-for-some-system?
  str : string?
  kind : (or/c 'unix 'windows)
```

Converts str to a kind path using a UTF-8 encoding of the path’s bytes.

Use this function when working with paths for a different system (whose encoding of pathnames might be unrelated to the current locale’s encoding) and when starting and ending with strings.

> ```
(shrink-path-wrt pth other-pths)  →  (or/c #f path?)
  pth : path?
  other-pths : (listof path?)
```
Returns a suffix of pth that shares nothing in common with the suffixes of other-pths, or pth, if not possible (e.g. when other-pths is empty or contains only paths with the same elements as pth).
Examples:
> ```racket
> > ( shrink-path-wrt ( build-path "racket" "list.rkt" ) ( list ( build-path "racket" "list.rkt" ) ( build-path "racket" "base.rkt" ) ) )
> #<path:list.rkt>
> > ( shrink-path-wrt ( build-path "racket" "list.rkt" ) ( list ( build-path "racket" "list.rkt" ) ( build-path "racket" "private" "list.rkt" ) ( build-path "racket" "base.rkt" ) ) )
> #<path:racket/list.rkt>
> ```
------------------------------------------------------------------------


# 15.1.3 Unix and Mac OS Paths


#### 15.1.3 Unix and Mac OS Paths
In a path on Unix and Mac OS, a / separates elements of the path, . as a path element always means the directory indicated by preceding path, and .. as a path element always means the parent of the directory indicated by the preceding path. A leading \~ in a path is not treated specially, but [expand-user-path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._expand-user-path%29%29) can be used to convert a leading \~ element to a user-specific directory. No other character or byte has a special meaning within a path. Multiple adjacent / are equivalent to a single / (i.e., they act as a single path separator).
A path root is always /. A path starting with / is an absolute, complete path, and a path starting with any other character is a relative path.
Any pathname that ends with a / syntactically refers to a directory, as does any path whose last element is . or ...
A Unix and Mac OS path is [cleanse](pathutils.html#%28tech._cleanse%29)d by replacing multiple adjacent /s with a single /.


# 15.1.3 Unix and Mac OS Paths
For ([bytes->path-element](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._bytes-~3epath-element%29%29) bstr), bstr must not contain any /, otherwise the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised. The result of ([path-element->bytes](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-element-~3ebytes%29%29) path) or ([path-element->string](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-element-~3estring%29%29) path) is always the same as the result of ([path->bytes](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-~3ebytes%29%29) path) and ([path->string](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-~3estring%29%29) path). Since that is not the case for other platforms, however, [path-element->bytes](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-element-~3ebytes%29%29) and [path-element->string](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-element-~3estring%29%29) should be used when converting individual path elements.
On Mac OS, Finder aliases are zero-length files.


##### 15.1.3.1 Unix Path Representation
A path on Unix and Mac OS is natively a byte string. For presentation to users and for other string-based operations, a path is converted to/from a string using the current locale’s encoding with ? (encoding) or #\\uFFFD (decoding) in place of errors. Beware that the encoding may not accommodate all possible paths as distinct strings.
------------------------------------------------------------------------


# 15.1.4 Windows Paths


#### 15.1.4 Windows Paths
In general, a Windows pathname consists of an optional drive specifier and a drive-specific path. A Windows path can be absolute but still relative to the current drive; such paths start with a / or \\ separator and are not UNC paths or paths that start with \\\\?\\.
A path that starts with a drive specification is complete. Roughly, a drive specification is either a Latin letter followed by a colon, a UNC path of the form \\\\‹machine›\\‹volume›, or a \\\\?\\ form followed by something other than REL\\‹element›, or RED\\‹element›. (Variants of \\\\?\\ paths are described further below.)
Racket fails to implement the usual Windows path syntax in one way. Outside of Racket, a pathname "C:rant.txt" can be a drive-specific relative path. That is, it names a file "rant.txt" on drive "C:", but the complete path to the file is determined by the current working directory for drive "C:". Racket does not support drive-specific working directories (only a working directory across all drives, as reflected by the [current-directory](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29) parameter). Consequently, Racket implicitly converts a path like "C:rant.txt" into "C:\\rant.txt".
-   Racket-specific: Whenever a path starts with a drive specifier ‹letter›: that is not followed by a / or \\, a \\ is inserted as the path is [cleanse](pathutils.html#%28tech._cleanse%29)d.


# 15.1.4 Windows Paths
Otherwise, Racket follows standard Windows path conventions, but also adds \\\\?\\REL and \\\\?\\RED conventions to deal with paths inexpressible in the standard convention, plus conventions to deal with excessive \\s in \\\\?\\ paths.
In the following, ‹letter› stands for a Latin letter (case does not matter), ‹machine› stands for any sequence of characters that does not include \\ or / and is not ?, ‹volume› stands for any sequence of characters that does not include \\ or / , and ‹element› stands for any sequence of characters that does not include \\.
-   Trailing spaces and . in a path element are ignored when the element is the last one in the path, unless the path starts with \\\\?\\ or the element consists of only spaces and .s.
-   The following special “files”, which access devices, exist in all directories, case-insensitively, and with all possible endings after a period or colon, except in pathnames that start with \\\\?\\: "NUL", "CON", "PRN", "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9".
-   Except for \\\\?\\ paths, /s are equivalent to \\s. Except for \\\\?\\ paths and the start of UNC paths, multiple adjacent /s and \\s count as a single \\. In a path that starts \\\\?\\ paths, elements can be separated by either a single or double \\.


# 15.1.4 Windows Paths
-   A directory can be accessed with or without a trailing separator. In the case of a non-\\\\?\\ path, the trailing separator can be any number of /s and \\s; in the case of a \\\\?\\ path, a trailing separator must be a single \\, except that two \\s can follow \\\\?\\‹letter›:.
-   Except for \\\\?\\ paths, a single . as a path element means “the current directory,” and a .. as a path element means “the parent directory.” Up-directory path elements (i.e., ..) immediately after a drive are ignored.
-   A pathname that starts \\\\‹machine›\\‹volume› (where a / can replace any \\) is a UNC path, and the starting \\\\‹machine›\\‹volume› counts as the drive specifier.
-   Normally, a path element cannot contain a character in the range #\\x 0 to #\\x 1F nor any of the following characters:
    > \< \> : " / \\ \| ? \*
    Except for \\, path elements containing these characters can be accessed using a \\\\?\\ path (assuming that the underlying filesystem allows the characters).
-   In a pathname that starts \\\\?\\‹letter›:\\, the \\\\?\\‹letter›:\\ prefix counts as the path’s drive, as long as the path does not both contain non-drive elements and end with two consecutive \\s, and as long as the path contains no sequence of three or more \\s. Two \\s can appear in place of the \\ before ‹letter›. A / cannot be used in place of a \\ (but /s can be used in element names, though the result typically does not name an actual directory or file).


# 15.1.4 Windows Paths
-   In a pathname that starts \\\\?\\UNC\\‹machine›\\‹volume›, the \\\\?\\UNC\\‹machine›\\‹volume› prefix counts as the path’s drive, as long as the path does not end with two consecutive \\s, and as long as the path contains no sequence of three or more \\s. Two \\s can appear in place of the \\ before UNC, the \\s after UNC, and/or the \\s after‹machine›. The letters in the UNC part can be uppercase or lowercase, and / cannot be used in place of \\s (but / can be used in element names).
-   Racket-specific: A pathname that starts \\\\?\\REL\\‹element› or \\\\?\\REL\\\\‹element› is a relative path, as long as the path does not end with two consecutive \\s, and as long as the path contains no sequence of three or more \\s. This Racket-specific path form supports relative paths with elements that are not normally expressible in Windows paths (e.g., a final element that ends in a space). The REL part must be exactly the three uppercase letters, and /s cannot be used in place of \\s. If the path starts \\\\?\\REL\\.. then for as long as the path continues with repetitions of \\.., each element counts as an up-directory element; a single \\ must be used to separate the up-directory elements. As soon as a second \\ is used to separate the elements, or as soon as a non-.. element is encountered, the remaining elements are all literals (never up-directory elements). When a \\\\?\\REL path value is converted to a string (or when the path value is written or displayed), the string does not contain the starting \\\\?\\REL or the immediately following \\s; converting a path value to a byte string preserves the \\\\?\\REL prefix.


# 15.1.4 Windows Paths
-   Racket-specific: A pathname that starts \\\\?\\RED\\‹element› or \\\\?\\RED\\\\‹element› is a drive-relative path, as long as the path does not end with two consecutive \\s, and as long as the path contains no sequence of three or more \\s. This Racket-specific path form supports drive-relative paths (i.e., absolute given a drive) with elements that are not normally expressible in Windows paths. The RED part must be exactly the three uppercase letters, and /s cannot be used in place of \\s. Unlike \\\\?\\REL paths, a .. element is always a literal path element. When a \\\\?\\RED path value is converted to a string (or when the path value is written or displayed), the string does not contain the starting \\\\?\\RED and it contains a single starting \\; converting a path value to a byte string preserves the \\\\?\\RED prefix.
Three additional Racket-specific rules provide meanings to character sequences that are otherwise ill-formed as Windows paths:
-   Racket-specific: In a pathname of the form \\\\?\\‹any›\\\\ where ‹any› is any non-empty sequence of characters other than ‹letter›: or \\‹letter›:, the entire path counts as the path’s (non-existent) drive.
-   Racket-specific: In a pathname of the form \\\\?\\‹any›\\\\\\‹elements›, where ‹any› is any non-empty sequence of characters and ‹elements› is any sequence that does not start with a \\, does not end with two \\s, and does not contain a sequence of three \\s, then \\\\?\\‹any›\\\\ counts as the path’s (non-existent) drive.


# 15.1.4 Windows Paths
-   Racket-specific: In a pathname that starts \\\\?\\ and does not match any of the patterns from the preceding bullets, \\\\?\\ counts as the path’s (non-existent) drive.
Outside of Racket, except for \\\\?\\ paths, pathnames are typically limited to 259 characters when used as a file path and 247 characters when used as a directory path. Racket internally converts pathnames longer than 247 characters to \\\\?\\ form to avoid the limits; in that case, the path is first simplified syntactically (in the sense of [simplify-path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._simplify-path%29%29)). The operating system cannot access files through \\\\?\\ paths that are longer than 32,000 characters or so.
Where the above descriptions says “character,” substitute “byte” for interpreting byte strings as paths. The encoding of Windows paths into bytes preserves ASCII characters, and all special characters mentioned above are ASCII, so all of the rules are the same.
Beware that the \\ path separator is an escape character in Racket strings. Thus, the path \\\\?\\REL\\..\\\\.. as a string must be written "\\\\\\\\?\\\\REL\\\\..\\\\\\\\..".
A path that ends with a directory separator syntactically refers to a directory. In addition, a path syntactically refers to a directory if its last element is a same-directory or up-directory indicator (not quoted by a \\\\?\\ form), or if it refers to a root.


# 15.1.4 Windows Paths
Even on variants of Windows that support symbolic links, up-directory .. indicators in a path are resolved syntactically, not sensitive to links. For example, if a path ends with d\\..\\f and d refers to a symbolic link that references a directory with a different parent than d, the path nevertheless refers to f in the same directory as d. A relative-path link is parsed as if prefixed with \\\\?\\REL paths, except that .. and . elements are allowed throughout the path, and any number of redundant \\ separators are allowed.
Windows paths are [cleanse](pathutils.html#%28tech._cleanse%29)d as follows: In paths that start \\\\?\\, redundant \\s are removed, an extra \\ is added in a \\\\?\\REL if an extra one is not already present to separate up-directory indicators from literal path elements, and an extra \\ is similarly added after \\\\?\\RED if an extra one is not already present. For other paths, multiple /s and \\s are converted to single /s or \\ (except at the beginning of a shared folder name), and a \\ is inserted after the colon in a drive specification if it is missing.


# 15.1.4 Windows Paths
For ([bytes->path-element](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._bytes-~3epath-element%29%29) bstr), /s, colons, trailing dots, trailing whitespace, and special device names (e.g., “aux”) in bstr are encoded as a literal part of the path element by using a \\\\?\\REL prefix. The bstr argument must not contain a \\, otherwise the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.
For ([path-element->bytes](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-element-~3ebytes%29%29) path) or ([path-element->string](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-element-~3estring%29%29) path), if the byte-string form of path starts with a \\\\?\\REL, the prefix is not included in the result.


# 15.1.4 Windows Paths
For ([build-path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._build-path%29%29) base-path sub-path [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29)), trailing spaces and periods are removed from the last element of base-path and all but the last sub-path (unless the element consists of only spaces and periods), except for those that start with \\\\?\\. If base-path starts \\\\?\\, then after each non-\\\\?\\REL\\ and non-\\\\?\\RED\\ sub-path is added, all /s in the addition are converted to \\s, multiple consecutive \\s are converted to a single \\, added . elements are removed, and added .. elements are removed along with the preceding element; these conversions are not performed on the original base-path part of the result or on any \\\\?\\REL\\ or \\\\?\\RED\\ or sub-path. If a \\\\?\\REL\\ or \\\\?\\RED\\ sub-path is added to a non-\\\\?\\ base-path, the base-path (with any additions up to the \\\\?\\REL\\ or \\\\?\\RED\\ sub-path) is simplified and converted to a \\\\?\\ path. In other cases, a \\ may be added or removed before combining paths to avoid changing the root meaning of the path (e.g., combining //x and y produces /x/y, because //x/y would be a UNC path instead of a drive-relative path).


# 15.1.4 Windows Paths
For ([simplify-path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._simplify-path%29%29) path use-filesystem?), path is expanded, and if path does not start with \\\\?\\, trailing spaces and periods are removed, a / is inserted after the colon in a drive specification if it is missing, and a \\ is inserted after \\\\?\\ as a root if there are elements and no extra \\ already. Otherwise, if no indicators or redundant separators are in path, then path is returned.
For ([split-path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._split-path%29%29) path) producing base, name, and must-be-dir?, splitting a path that does not start with \\\\?\\ can produce parts that start with \\\\?\\. For example, splitting C:/x /aux/ twice produces \\\\?\\REL\\\\x  and \\\\?\\REL\\\\aux; the \\\\?\\ is needed in these cases to preserve a trailing space after x and to avoid referring to the AUX device instead of an "aux" file.


##### 15.1.4.1 Windows Path Representation
A path on Windows is natively a sequence of UTF-16 code units, where the sequence can include unpaired surrogates. This sequence is encoded as a byte string through an extension of UTF-8, where unpaired surrogates in the UTF-16 code-unit sequence are converted as if they were non-surrogate values. The extended encodings are implemented on Windows as the "platform-UTF-16" and "platform-UTF-8" encodings for [bytes-open-converter](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes-open-converter%29%29).
Racket’s internal representation of a Windows path is a byte string, so that [path->bytes](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._path-~3ebytes%29%29) and [bytes->path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._bytes-~3epath%29%29) are always inverses. When converting a path to a native UTF-16 code-unit sequence, #\\tab is used in place of platform-UTF-8 decoding errors (on the grounds that tab is normally disallowed as a character in a Windows path, unlike #\\uFFFD).
A Windows path is converted to a string by treating the platform-UTF-8 encoding as a UTF-8 encoding with #\\uFFFD in place of decoding errors. Similarly, a string is converted to a path by UTF-8 encoding (in which case no errors are possible).
------------------------------------------------------------------------


# 15.2 Filesystem


### 15.2 Filesystem


#### 15.2.1 Locating Paths
> ```
(parameter)	→
```
(parameter)	→
(-> listof (or/c path? 'same))```

Parses a string or byte string containing a list of paths, and returns a list of paths. On Unix and Mac OS, paths in a path-list string are separated by a :; on Windows, paths are separated by a ;, and all "s in the string are discarded. Whenever the path list contains an empty path, the list default-path-list is spliced into the returned list of paths. Parts of str that do not form a valid path are not included in the returned list. The given str must not contain a nul character or nul byte.

Changed in version 8.0.0.10 of package base: Changed to allow 'same in default-path-list.

> ```
(find-executable-path program
   [ related
    deepest?)    →    (or/c path? #f)

  program : path-string?
  related : (or/c path-string? #f) = #f
  deepest? : any/c = #f
```
Finds a path for the executable program, returning #f if the path cannot be found.
On Windows, if program is not found and it has no file extension, then the search starts over with ".exe" added to program, and the result is #f only if the path with ".exe" also cannot be found. The result includes the extension ".exe" if only program with the extension is found.
If related is not #f, then it must be a relative path string, and the path found for program must be such that the file or directory related exists in the same directory as the executable. The result is then the full path for the found related, instead of the path for the executable.


# 15.2 Filesystem
This procedure is used by the Racket executable to find the standard library collection directory (see Libraries and Collections). In this case, program is the name used to start Racket and related is "collects". The related argument is used because, on Unix and Mac OS, program may involve a sequence of soft links; in this case, related determines which link in the chain is relevant.
If related is not #f, then when find-executable-path does not find a program that is a link to another file path, the search can continue with the destination of the link. Further links are inspected until related is found or the end of the chain of links is reached. If deepest? is #f (the default), then the result corresponds to the first path in a chain of links for which related is found (and further links are not actually explored); otherwise, the result corresponds to the last link in the chain for which related is found.
If program is a pathless name, find-executable-path gets the value of the PATH environment variable; if this environment variable is defined, find-executable-path tries each path in PATH as a prefix for program using the search algorithm described above for path-containing programs. If the PATH environment variable is not defined, program is prefixed with the current directory and used in the search algorithm above. (On Windows, the current directory is always implicitly the first item in PATH, so find-executable-path checks the current directory first on Windows.)
Changed in version 8.1.0.7 of package base: Added search with ".exe" on Windows.


#### 15.2.2 Files
> ```
(file-exists? path)   →   boolean?
  path : path-string?```
Returns #t if a file (not a directory) path exists, #f otherwise.
On Windows, [file-exists?](#%28def._%28%28quote._~23~25kernel%29._file-exists~3f%29%29) reports #t for all variations of the special filenames (e.g., "LPT1", "x:/baddir/LPT1").
> ```
(link-exists? path)  →  boolean?
  path : path-string?
```
Returns #t if a link path exists, #f otherwise.

The predicates file-exists? or directory-exists? work on the final destination of a link or series of links, while link-exists? only follows links to resolve the base part of path (i.e., everything except the last name in the path).

This procedure never raises the exn:fail:filesystem exception.

On Windows, link-exists? reports #t for both symbolic links and junctions.

Changed in version 6.0.1.12 of package base: Added support for links on Windows.

> ```
(file-or-directory-type path [must-exist?)
   →   (or/c 'file 'directory 'link 'directory-link #f)
  path : path-string?
  must-exist? : any/c = #f```

Reports whether path refers to a file, directory, link, or directory link (in the case of Windows; see also [make-file-or-directory-link](#%28def._%28%28quote._~23~25kernel%29._make-file-or-directory-link%29%29)), assuming that path can be accessed.

If path cannot be accessed, the result is #f if must-exist? is #f, otherwise the [exn:fail:filesystem](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3afilesystem%29%29) exception is raised.

Added in version 7.8.0.5 of package base.

> ```
(parameter)	→
```


# 15.2 Filesystem
(parameter)	→```
Renames the file or directory with path old—if it exists—to the path new. If the file or directory is not renamed successfully, the [exn:fail:filesystem](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3afilesystem%29%29) exception is raised.
This procedure can be used to move a file/directory to a different directory (on the same filesystem) as well as rename a file/directory within a directory. Unless exists-ok? is provided as a true value, new cannot refer to an existing file or directory, but the check is not atomic with the rename operation on Unix and Mac OS. Even if exists-ok? is true, new cannot refer to an existing file when old is a directory, and vice versa.
If new exists and is replaced, the replacement is atomic on Unix and Mac OS, but it is not guaranteed to be atomic on Windows. Furthermore, if new exists and is opened by any process for reading or writing, then attempting to replace it will typically fail on Windows. See also [call-with-atomic-output-file](#%28def._%28%28lib._racket%2Ffile..rkt%29._call-with-atomic-output-file%29%29).
If old is a link, the link is renamed rather than the destination of the link, and it counts as a file for replacing any existing new.


# 15.2 Filesystem
On Windows, beware that a directory cannot be renamed if any file within the directory is open. That constraint is particularly problematic if a search indexer is running in the background (as in the default Windows configuration). A possible workaround is to combine [copy-directory/files](#%28def._%28%28lib._racket%2Ffile..rkt%29._copy-directory%2Ffiles%29%29) and [delete-directory/files](#%28def._%28%28lib._racket%2Ffile..rkt%29._delete-directory%2Ffiles%29%29), since the latter can deal with open files, although that sequence is obviously not atomic and temporarily duplicates files.
> ```
(parameter)	→
(-> file-or-directory-modify-seconds path
    secs-n)


# 15.2 Filesystem
```
Returns the file or directory’s last modification date in seconds since the epoch (see also Time) when secs-n is not provided or is #f.

For FAT filesystems on Windows, directories do not have modification dates. Therefore, the creation date is returned for a directory, but the modification date is returned for a file.

If secs-n is provided and not #f, the access and modification times of path are set to the given time.

On error (e.g., if no such file exists), then fail-thunk is called (through a tail call) to produce the result of the file-or-directory-modify-seconds call. If fail-thunk is not provided, an error raises exn:fail:filesystem.

> ```
(file-or-directory-permissions path [mode)
   →   (listof (or/c 'read 'write 'execute))
  path : path-string?
  mode : #f = #f
(file-or-directory-permissions path mode)   →   (integer-in 0 65535)
  path : path-string?
  mode : 'bits
(file-or-directory-permissions path mode)   →   void
  path : path-string?
  mode : (integer-in 0 65535)```

When given one argument or #f as the second argument, returns a list containing 'read, 'write, and/or 'execute to indicate permission the given file or directory path by the current user and group. On Unix and Mac OS, permissions are checked for the current effective user instead of the real user.

If 'bits is supplied as the second argument, the result is a platform-specific integer encoding of the file or directory properties (mostly permissions), and the result is independent of the current user and group. The lowest nine bits of the encoding are somewhat portable, reflecting permissions for the file or directory’s owner, members of the file or directory’s group, or other users:

-   #o400 : owner has read permission

-   #o200 : owner has write permission

-   #o100 : owner has execute permission

-   #o040 : group has read permission

-   #o020 : group has write permission

-   #o010 : group has execute permission

-   #o004 : others have read permission

-   #o002 : others have write permission

-   #o001 : others have execute permission

See also [user-read-bit](#%28def._%28%28lib._racket%2Ffile..rkt%29._user-read-bit%29%29), etc. On Windows, permissions from all three (owner, group, and others) are always the same, and read and execute permission are always available. On Unix and Mac OS, higher bits have a platform-specific meaning.

If an integer is supplied as the second argument, it is used as an encoding of properties (mostly permissions) to install for the file.

In all modes, the [exn:fail:filesystem](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3afilesystem%29%29) exception is raised on error (e.g., if no such file exists).

> ```
(parameter)	→
(-> and/c (hash/c symbol? any/c) hash-eq?)
```


# 15.2 Filesystem
Returns a hash with the following keys and values, where each value currently is a nonnegative exact integer:
-  'device-id : device ID
-  'inode : inode number
-  'mode : mode bits (see below)
-  'hardlink-count : number of hard links
-  'user-id : numeric user ID of owner
-  'group-id : numeric group ID of owner
-  'device-id-for-special-file : device ID (if special file)
-  'size : size of file or symbolic link in bytes
-  'block-size : size of filesystem blocks
-  'block-count : number of used filesystem blocks
-  'access-time-seconds : last access time in seconds since the epoch
-  'modify-time-seconds : last modification time in seconds since the epoch
-  'change-time-seconds : last status change time in seconds since the epoch
-  'creation-time-seconds : creation time in seconds since the epoch
-  'access-time-nanoseconds : last access time in nanoseconds since the epoch
-  'modify-time-nanoseconds : last modification time in nanoseconds since the epoch
-  'change-time-nanoseconds : last status change time in nanoseconds since the epoch
-  'creation-time-nanoseconds : creation time in nanoseconds since the epoch
If as-link? is a true value, then if path refers to a symbolic link, the stat information of the link is returned instead of the stat information of the referenced filesystem item.
The mode bits are the bits for permissions and other data, as returned from the Posix stat/lstat functions or the Windows \_wstat64 function, respectively. To select portions of the bit pattern, use the constants user-read-bit, etc.


# 15.2 Filesystem
Depending on the operating system and filesystem, the “nanoseconds” timestamps may have less than nanoseconds precision. For example, in one environment a timestamp may be 1234567891234567891 (nanoseconds precision) and in another environment 1234567891000000000 (seconds precision).
Values that aren’t available for a platform/filesystem combination may be set to 0. For example, this applies to the 'user-id and 'group-id keys on Windows. Also, Posix platforms provide the status change timestamp, but not the creation timestamp; for Windows it’s the opposite.
If as-link? is #f and path isn’t accessible, the exn:fail:filesystem exception is raised. This exception is also raised if as-link? is a true value and path can’t be resolved, i.e., is a dangling link.
Added in version 8.3.0.7 of package base.
> ```
(file-or-directory-identity path [as-link?)
   →   exact-positive-integer?
  path : path-string?
  as-link? : any/c = #f```
Returns a number that represents the identity of path in terms of the device and file or directory that it accesses. This function can be used to check whether two paths correspond to the same filesystem entity under the assumption that the path’s entity selection does not change.
If as-link? is a true value, then if path refers to a filesystem link, the identity of the link is returned instead of the identity of the referenced file or directory (if any).
> ```
(file-size path)  →  exact-nonnegative-integer?
  path : path-string?


# 15.2 Filesystem
```
(logical)	→
(-> or/c #f (integer-in 0 65535))```

Creates the file dest as a copy of src, if dest does not already exist. If dest already exists and exists-ok? is #f, the copy fails and the [exn:fail:filesystem:exists?](exns.html#%28def._%28%28quote._~23~25kernel%29._exn~3afail~3afilesystem~3aexists~3f%29%29) exception is raised; otherwise, if dest exists, its content is replaced with the content of src.

If src refers to a link, the target of the link is copied, rather than the link itself. If dest refers to a link and exists-ok? is true, the target of the link is updated.

File permissions are transferred from src to dest, unless permissions is supplied as non-#f on Unix and Mac OS, in which case permissions is used for dest. Beware that permissions are transferred without regard for the process’s umask setting by default, but see replace-permissions? below. On Windows, the modification time of src is also transferred to dest; if permissions is supplied as non-#f, then after copying, dest is set to read-only or not depending on whether the #o2 bit is present in permissions.

The replace-permissions? argument is used only on Unix and Mac OS. When dests is created, it is created with permissions or the permissions of src; however, the process’s umask may unset bits in the requested permissions. When dest already exists (and exists-ok? is true), then the permissions of dest are initially left as-is. Finally, when replace-permissions? is a true value, then the permissions of dest are set after the file content is copied to permissions or the permissions of src, without modification by umask.

The exists-ok?/pos by-position argument is for backward compatibility. That by-position argument can be supplied, or the exists-ok? keyword argument can be supplied, but the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised if both are supplied.

Changed in version 8.7.0.9 of package base: Added #:exists-ok?, #:permissions, and #:replace-permissions? arguments.

> ```
(parameter)	→
```


# 15.2 Filesystem
(current-force-delete-permissions)	→
(-> current-force-delete-permissions)```
A [parameter](eval-model.html#%28tech._parameter%29) that determines on Windows whether [delete-file](#%28def._%28%28quote._~23~25kernel%29._delete-file%29%29) and [delete-directory](#%28def._%28%28quote._~23~25kernel%29._delete-directory%29%29) attempt to change a file or directory’s permissions to delete it. The default value is #t.


#### 15.2.3 Directories
See also: [rename-file-or-directory](#%28def._%28%28quote._~23~25kernel%29._rename-file-or-directory%29%29), [file-or-directory-modify-seconds](#%28def._%28%28quote._~23~25kernel%29._file-or-directory-modify-seconds%29%29), [file-or-directory-permissions](#%28def._%28%28quote._~23~25kernel%29._file-or-directory-permissions%29%29).
> ```
(current-directory)	→
(-> and/c path? complete-path?)
(current-directory path) → void?
    path	:
(-> and/c path? complete-path?)
```
(current-directory-for-user)	→
(-> current-directory-for-user)
(current-directory-for-user path) → void?
    path	:
(-> current-directory-for-user)```

Like [current-directory](#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29), but for use only by [srcloc->string](exns.html#%28def._%28%28quote._~23~25kernel%29._srcloc-~3estring%29%29) for reporting paths relative to a directory.

Normally, [current-directory-for-user](#%28def._%28%28quote._~23~25kernel%29._current-directory-for-user%29%29) should stay at its initial value, reflecting the directory where a user started a process. A tool such as DrRacket, however, implicitly lets a user select a directory (for the file being edited), in which case updating [current-directory-for-user](#%28def._%28%28quote._~23~25kernel%29._current-directory-for-user%29%29) makes sense.

> ```
(current-drive)	→
```
Returns the current drive name Windows. For other platforms, the exn:fail:unsupported exception is raised. The current drive is always the drive of the current directory.
> ```


# 15.2 Filesystem
(directory-exists? path)   →   boolean?
  path : path-string?```
Returns #t if path refers to a directory, #f otherwise.
> ```
(parameter)	→
(-> integer-in 0 65535)
```
(parameter)	→```

Deletes an existing directory with the path path. If the directory is not deleted successfully, the [exn:fail:filesystem](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3afilesystem%29%29) exception is raised.

On Windows, if an initial attempt to delete the directory fails with a permission error and the value of [current-force-delete-permissions](#%28def._%28%28quote._~23~25kernel%29._current-force-delete-permissions%29%29) is true, then [delete-file](#%28def._%28%28quote._~23~25kernel%29._delete-file%29%29) attempts to change the directory’s permissions (to allow writes) and then delete the directory; the permission change followed by deletion is a non-atomic sequence, with no attempt to revert a permission change if the deletion fails.

Changed in version 6.1.1.7 of package base: Changed Windows behavior to use [current-force-delete-permissions](#%28def._%28%28quote._~23~25kernel%29._current-force-delete-permissions%29%29).

> ```
(current-directory)	→
(-> listof path?)
```
> > > See also the in-directory sequence constructor.
Returns a list of all files and directories in the directory specified by path. If build? is #f, the resulting paths are all path elements; otherwise, the individual results are combined with path using build-path. On Windows, an element of the result list may start with \\\\?\\REL\\\\.


# 15.2 Filesystem
The resulting paths are always sorted using path<?.
> ```
(filesystem-root-list)   →   (listof path?)```
Returns a list of all current root directories. Obtaining this list can be particularly slow on Windows.


#### 15.2.4 Detecting Filesystem Changes
Many operating systems provide notifications for filesystem changes, and those notifications are reflected in Racket by [filesystem change events](#%28tech._filesystem._change._event%29).
> ```
(filesystem-change-evt? v)  →  boolean?
  v : any/c
```
Returns #t if v is a filesystem change event, #f otherwise.

> ```
(filesystem-change-evt path [failure-thunk)
   →   (or/c filesystem-change-evt? any)
  path : path-string?
  failure-thunk : (or/c (  →   any) #f) = #f```

Creates a filesystem change event, which is a [synchronizable event](sync.html#%28tech._synchronizable._event%29) that becomes [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) after a change to path:

-   If path refers to a file, the event becomes [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) when the file’s content or attributes change, or when the file is deleted.

-   If path refers to a directory, the event becomes [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) if a file or subdirectory is added, renamed, or removed within the directory.

The event also becomes [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) if it is passed to [filesystem-change-evt-cancel](#%28def._%28%28quote._~23~25kernel%29._filesystem-change-evt-cancel%29%29).

Finally, depending on the precision of information available from the operating system, the event may become [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) under other circumstances. For example, on Windows, an event for a file becomes ready when any file changes within in the same directory as the file.

After a [filesystem change event](#%28tech._filesystem._change._event%29) becomes [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29), it stays [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29). The event’s [synchronization result](sync.html#%28tech._synchronization._result%29) is the event itself.

If the current platform does not support filesystem-change notifications, then the [exn:fail:unsupported](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3aunsupported%29%29) exception is raised if failure-thunk is not provided as a procedure, or failure-thunk is called in tail position if provided. Similarly, if there is any operating-system error when creating the event (such as a non-existent file), then the [exn:fail:filesystem](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3afilesystem%29%29) exception is raised or failure-thunk is called.

Creation of a filesystem change event allocates resources at the operating-system level. The resources are released at latest when the event is sychronized and [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29), when the event is canceled with [filesystem-change-evt-cancel](#%28def._%28%28quote._~23~25kernel%29._filesystem-change-evt-cancel%29%29), or when the garbage collector determine that the filesystem change event is unreachable. See also [system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) in 'fs-change mode.

A filesystem change event is placed under the management of the [current custodian](eval-model.html#%28tech._current._custodian%29) when it is created. If the [custodian](eval-model.html#%28tech._custodian%29) is shut down, [filesystem-change-evt-cancel](#%28def._%28%28quote._~23~25kernel%29._filesystem-change-evt-cancel%29%29) is applied to the event.

Changed in version 7.3.0.8 of package base: Allow #f for failure-thunk.

> ```
(filesystem-change-evt-ready? evt)  →  boolean?
  evt : filesystem-change-evt?
```


# 15.2 Filesystem
(parameter)	→```
Causes evt to become immediately [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29), whether it was ready or not before, and releases the resources (at the operating-system level) for tracking filesystem changes.


#### 15.2.5 Declaring Paths Needed at Run Time
|                                                                                |                                                                                |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/runtime-path](#%28mod-path._racket%2Fruntime-path%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/runtime-path](#%28mod-path._racket%2Fruntime-path%29) library, not [racket/base](index.html) or [racket](index.html).


# 15.2 Filesystem
The [racket/runtime-path](#%28mod-path._racket%2Fruntime-path%29) library provides forms for accessing files and directories at run time using a path that are usually relative to an enclosing source file. Unlike using [collection-path](collects.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._collection-path%29%29), [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) exposes each run-time path to tools like the executable and distribution creators, so that files and directories needed at run time are carried along in a distribution.
In addition to the bindings described below, [racket/runtime-path](#%28mod-path._racket%2Fruntime-path%29) provides [#%datum](quote.html#%28form._%28%28quote._~23~25kernel%29._~23~25datum%29%29) in [phase level](syntax-model.html#%28tech._phase._level%29) 1, since string constants are often used as compile-time expressions with [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29).
>
<colgroup><col style="width: 100%" /></colgroup>

syntax


# 15.2 Filesystem

([define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) id maybe-runtime?-id expr)

<colgroup><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /></colgroup>

maybe-runtime?-id	 	=

 	 	|	 	#:runtime?-id runtime?-id


# 15.2 Filesystem
Uses expr as both a compile-time (i.e., [phase](eval-model.html#%28tech._phase%29) 1) expression and a run-time (i.e., [phase](eval-model.html#%28tech._phase%29) 0) expression. In either context, expr should produce a path, a string that represents a path, a list of the form ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'lib str ...+), or a list of the form ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'so str) or ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'so str vers). If runtime?-id is provided, then it is bound in the context of expr to #f for the compile-time instance of expr and #t for the run-time instance of expr.
For run time, id is bound to a path that is based on the result of expr. The path is normally computed by taking a relative path result from expr and adding it to a path for the enclosing file (which is computed as described below). However, tools like the executable creator can also arrange (by colluding with [racket/runtime-path](#%28mod-path._racket%2Fruntime-path%29)) to have a different base path substituted in a generated executable. If expr produces an absolute path, it is normally returned directly, but again may be replaced by an executable creator. In all cases, the executable creator preserves the relative locations of all paths within a given [package](collects.html#%28tech._package%29) (treating paths outside of any package as being together). When expr produces a relative or absolute path, then the path bound to id is always an absolute path.


# 15.2 Filesystem
If expr produces a list of the form ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'lib str ...+), the value bound to id is an absolute path. The path refers to a collection-based file similar to using the value as a [module path](Module_Names_and_Loading.html#%28tech._module._path%29).
If expr produces a list of the form ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'so str) or ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'so str vers), the value bound to id can be either str or an absolute path; it is an absolute path when searching in the Racket-specific shared-object library directories (as determined by [get-lib-search-dirs](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=dirs.html%23%2528def._%2528%2528lib._setup%252Fdirs..rkt%2529._get-lib-search-dirs%2529%2529&version=8.18.0.13)) locates the path. In this way, shared-object libraries that are installed specifically for Racket get carried along in distributions. The search tries each directory in order; within a directory, the search tries using str directly, then it tries adding each version specified by vers—which defaults to '(#f)—along with a platform-specific shared-library extension—as produced by ([system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'so-suffix). A vers can be a string, or it can be a list of strings and #f.


# 15.2 Filesystem
If expr produces a list of the form ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'share str), the value bound to id can be either str or an absolute path; it is an absolute path when searching in the directories reported by [find-user-share-dir](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=dirs.html%23%2528def._%2528%2528lib._setup%252Fdirs..rkt%2529._find-user-share-dir%2529%2529&version=8.18.0.13) and [find-share-dir](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=dirs.html%23%2528def._%2528%2528lib._setup%252Fdirs..rkt%2529._find-share-dir%2529%2529&version=8.18.0.13) (in that order) locates the path. In this way, files that are installed in Racket’s "share" directory get carried along in distributions.


# 15.2 Filesystem
If expr produces a list of the form ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'module module-path var-ref) or ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'so str ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) str-or-false [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29))), the value bound to id is a [module path index](Module_Names_and_Loading.html#%28tech._module._path._index%29), where module-path is treated as relative (if it is relative) to the module that is the home of the [variable reference](Locations____variable-reference.html#%28tech._variable._reference%29) var-ref, where var-ref can be #f if module-path is absolute. In an executable, the corresponding module is carried along, including all of its dependencies.


# 15.2 Filesystem
For compile-time, the expr result is used by an executable creator—but not the result when the containing module is compiled. Instead, expr is preserved in the module as a compile-time expression (in the sense of [begin-for-syntax](begin.html#%28form._%28%28quote._~23~25kernel%29._begin-for-syntax%29%29)). Later, at the time that an executable is created, the compile-time portion of the module is executed (again), and the result of expr is the file or directory to be included with the executable. The reason for the extra compile-time execution is that the result of expr might be platform-dependent, so the result should not be stored in the (platform-independent) bytecode form of the module; the platform at executable-creation time, however, is the same as at run time for the executable. Note that expr is still evaluated at run time; consequently, avoid procedures like [collection-path](collects.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._collection-path%29%29), which depends on the source installation, and instead use relative paths and forms like ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'lib str ...+).
If a path is needed only on some platforms and not on others, use [define-runtime-path-list](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path-list%29%29) with an expr that produces an empty list on platforms where the path is not needed.


# 15.2 Filesystem
Beware that if expr produces the path of a directory when creating an executable, the directory’s full content (including any subdirectories) is included with the executable or eventual distribution.
Also beware that [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) in a [phase level](syntax-model.html#%28tech._phase._level%29) other than 0 does not cooperate properly with an executable creator. To work around that limitation, put [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) in a separate module—perhaps a [submodule](eval-model.html#%28tech._submodule%29) created by [module](module.html#%28form._%28%28quote._~23~25kernel%29._module%29%29)—then export the definition, and then the module containing the definition can be [require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29)d into any phase level. Using [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) in a [phase level](syntax-model.html#%28tech._phase._level%29) other than 0 logs a warning at expansion time.
The enclosing path for a [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) is determined as follows from the [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) syntactic form:


# 15.2 Filesystem
-   If the form has a source module according to [syntax-source-module](stxops.html#%28def._%28%28quote._~23~25kernel%29._syntax-source-module%29%29), then the source location is determined by preserving the original expression as a syntax object, extracting its source module path at run time (again using [syntax-source-module](stxops.html#%28def._%28%28quote._~23~25kernel%29._syntax-source-module%29%29)), and then resolving the resulting module path index. Note that [syntax-source-module](stxops.html#%28def._%28%28quote._~23~25kernel%29._syntax-source-module%29%29) is based on a syntax object’s [lexical information](syntax-model.html#%28tech._lexical._information%29), not its source location.
-   If the expression has no source module, the [syntax-source](stxops.html#%28def._%28%28quote._~23~25kernel%29._syntax-source%29%29) location associated with the form is used, if is a string or path.
-   If no source module is available, and [syntax-source](stxops.html#%28def._%28%28quote._~23~25kernel%29._syntax-source%29%29) produces no path, then [current-load-relative-directory](eval.html#%28def._%28%28quote._~23~25kernel%29._current-load-relative-directory%29%29) is used if it is not #f. Finally, [current-directory](#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29) is used if all else fails.


# 15.2 Filesystem
In the latter two cases, the path is normally preserved in (platform-specific) byte form, but if the enclosing path corresponds to a result of [collection-file-path](collects.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._collection-file-path%29%29), then the path is record as relative to the corresponding module path.
Changed in version 6.0.1.6 of package base: Preserve relative paths only within a package.
Changed in version 7.5.0.7: Added support for 'share in expr.
Examples:
> ```racket
> ; Access a file "data.txt" at run-time that is originally
> ; located in the same directory as the module source file:
> ( define-runtime-path data-file "data.txt" )
> ( define ( read-data )
> ( with-input-from-file data-file
> ( lambda ( )
> ( read-bytes ( file-size data-file ) ) ) ) )
> ; Load a platform-specific shared object (using ffi-lib )
> ; that is located in a platform-specific sub-directory of the
> ; module ' s source directory:
> ( define-runtime-path libfit-path
> ( build-path "compiled" "native" ( system-library-subpath #f )
> ( path-replace-suffix "libfit"
> ( system-type ' so-suffix ) ) ) )
> ( define libfit ( ffi-lib libfit-path ) )
> ; Load a platform-specific shared object that might be installed
> ; as part of the operating system, or might be installed
> ; specifically for Racket:
> ( define-runtime-path libssl-so
> ( case ( system-type )
> [ ( windows ) ' ( so "ssleay32" ) ]
> [ else ' ( so "libssl" ) ] ) )
> ( define libssl ( ffi-lib libssl-so ) )
> ```
Changed in version 6.4 of package base: Added #:runtime?-id.


# 15.2 Filesystem
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([define-runtime-paths](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-paths%29%29) (id ...) maybe-runtime?-id expr)

Like [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29), but declares and binds multiple paths at once. The expr should produce as many values as ids.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([define-runtime-path-list](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path-list%29%29) id maybe-runtime?-id expr)

Like [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29), but expr should produce a list of paths.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([define-runtime-module-path-index](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path-index%29%29) id maybe-runtime?-id module-path-expr)


# 15.2 Filesystem
Similar to [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29), but id is bound to a [module path index](Module_Names_and_Loading.html#%28tech._module._path._index%29) that encapsulates the result of module-path-expr relative to the enclosing module.
Use [define-runtime-module-path-index](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path-index%29%29) to bind a module path that is passed to a reflective function like [dynamic-require](Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29) while also creating a module dependency for building and distributing executables.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([runtime-require](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._runtime-require%29%29) module-path)

Similar to [define-runtime-module-path-index](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path-index%29%29), but creates the distribution dependency without binding a module path index. When [runtime-require](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._runtime-require%29%29) is used multiple times within a module with the same module-path, all but the first use expands to an empty [begin](begin.html#%28form._%28%28quote._~23~25kernel%29._begin%29%29).


# 15.2 Filesystem
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([define-runtime-module-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path%29%29) id module-path)

Similar to [define-runtime-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29), but id is bound to a [resolved module path](Module_Names_and_Loading.html#%28tech._resolved._module._path%29). The [resolved module path](Module_Names_and_Loading.html#%28tech._resolved._module._path%29) for id corresponds to module-path (with the same syntax as a module path for [require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29)), which can be relative to the enclosing module.


# 15.2 Filesystem
The [define-runtime-module-path-index](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path-index%29%29) form is usually preferred, because it creates a weaker link to the referenced module. Unlike [define-runtime-module-path-index](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path-index%29%29), the [define-runtime-module-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path%29%29) form creates a [for-label](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for-label%29%29) dependency from an enclosing module to module-path. Since the dependency is merely [for-label](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for-label%29%29), module-path is not [instantiate](eval-model.html#%28tech._instantiate%29)d or [visit](syntax-model.html#%28tech._visit%29)ed when the enclosing module is [instantiate](eval-model.html#%28tech._instantiate%29)d or [visit](syntax-model.html#%28tech._visit%29)ed (unless such a dependency is created by other [require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29)s), but the code for the referenced module is loaded when the enclosing module is loaded.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([runtime-paths](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._runtime-paths%29%29) module-path)


# 15.2 Filesystem
This form is mainly for use by tools such as executable builders. It expands to a quoted list containing the run-time paths declared by module-path, returning the compile-time results of the declaration exprs, except that paths are converted to byte strings. The enclosing module must require (directly or indirectly) the module specified by module-path, which is an unquoted module path. The resulting list does not include module paths bound through [define-runtime-module-path](#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-module-path%29%29).


#### 15.2.6 More File and Directory Utilities
|                                                                                |                                                                                |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/file](#%28mod-path._racket%2Ffile%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/file](#%28mod-path._racket%2Ffile%29) and [racket](index.html) libraries, but not [racket/base](index.html).
> ```
(file → string path [#:mode mode-flag) → string?
  path : path-string?
  mode-flag : (or/c 'binary 'text) = 'binary


# 15.2 Filesystem
```
Reads all characters from path and returns them as a string. The mode-flag argument is the same as for open-input-file.

> ```
(file → bytes path [#:mode mode-flag) → bytes?
  path : path-string?
  mode-flag : (or/c 'binary 'text) = 'binary```

Reads all characters from path and returns them as a [byte string](bytestrings.html#%28tech._byte._string%29). The mode-flag argument is the same as for [open-input-file](file-ports.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._open-input-file%29%29).

> ```
(file → value path [#:mode mode-flag) → any
  path : path-string?
  mode-flag : (or/c 'binary 'text) = 'binary
```
Reads a single S-expression from path using read. The mode-flag argument is the same as for open-input-file.
> ```
(file → list path [proc #:mode mode-flag) → (listof any/c)
  path : path-string?
  proc : (input-port? .  →  . any/c) = read
  mode-flag : (or/c 'binary 'text) = 'binary```
Repeatedly calls proc to consume the contents of path, until [eof](port-ops.html#%28def._%28%28quote._~23~25kernel%29._eof%29%29) is produced. The mode-flag argument is the same as for [open-input-file](file-ports.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._open-input-file%29%29).
> ```
(file → lines path
   [ #:mode mode-flag
    #:line-mode line-mode)    →    (listof string?)
  path : path-string?
  mode-flag : (or/c 'binary 'text) = 'binary
   line-mode   :   (or/c 'linefeed 'return 'return-linefeed 'any 'any-one)
      =   'any


# 15.2 Filesystem
```
Read all characters from path, breaking them into lines. The line-mode argument is the same as the second argument to read-line, but the default is 'any instead of 'linefeed. The mode-flag argument is the same as for open-input-file.

> ```
(file → bytes-lines path
   [ #:mode mode-flag
    #:line-mode line-mode)    →    (listof bytes?)

  path : path-string?
  mode-flag : (or/c 'binary 'text) = 'binary
   line-mode   :   (or/c 'linefeed 'return 'return-linefeed 'any 'any-one)
      =   'any```

Like [file->lines](#%28def._%28%28lib._racket%2Ffile..rkt%29._file-~3elines%29%29), but reading bytes and collecting them into lines like [read-bytes-line](Byte_and_String_Input.html#%28def._%28%28quote._~23~25kernel%29._read-bytes-line%29%29).

> ```
(parameter)	→
(-> or/c 'binary 'text)
```
(parameter)	→
(-> or/c 'binary 'text)```
Like [display-to-file](#%28def._%28%28lib._racket%2Ffile..rkt%29._display-to-file%29%29), but using [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) instead of [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29).
> ```
(parameter)	→
(-> or/c 'binary 'text)


# 15.2 Filesystem
```
(parameter)	→```

Copies the file or directory src to dest, raising [exn:fail:filesystem](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3afilesystem%29%29) if the file or directory cannot be copied, possibly because dest exists already. If src is a directory, the copy applies recursively to the directory’s content. If a source is a link and preserve-links? is #f, the target of the link is copied rather than the link itself; if preserve-links? is #t, the link is copied.

If keep-modify-seconds? is #f, then file copies keep only the properties kept by [copy-file](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._copy-file%29%29). If keep-modify-seconds? is true, then each file copy also keeps the modification date of the original.

Changed in version 6.3 of package base: Added the #:preserve-links? argument.

> ```
(parameter)	→
```
Deletes the file or directory specified by path, raising exn:fail:filesystem if the file or directory cannot be deleted. If path is a directory, then delete-directory/files is first applied to each file and directory in path before the directory is deleted.
If must-exist? is true, then exn:fail:filesystem is raised if path does not exist. If must-exist? is false, then delete-directory/files succeeds if path does not exist (but a failure is possible if path initially exists and is removed by another thread or process before delete-directory/files deletes it).


# 15.2 Filesystem
On Windows, delete-directory/files attempts to move a file into the temporary-file directory before deleting it, which avoids problems caused by deleting a file that is currently open (e.g., by a search indexer running as a background process). If the move attempt fails (e.g., because the temporary directory is on a different drive than the file), then the file is deleted directly with delete-file.
Changed in version 7.0 of package base: Added Windows-specific file deletion.
> ```
(find-files
    predicate
   [ start-path
    #:skip-filtered-directory? skip-filtered-directory?
    #:follow-links? follow-links?)
   →   (listof path?)
  predicate : (path? .  →  . any/c)
  start-path : (or/c path-string? #f) = #f
  skip-filtered-directory? : any/c = #f
  follow-links? : any/c = #f```
Traverses the filesystem starting at start-path and creates a list of all files and directories for which predicate returns true. If start-path is #f, then the traversal starts from ([current-directory](#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29)). In the resulting list, each directory precedes its content.


# 15.2 Filesystem
The predicate procedure is called with a single argument for each file or directory. If start-path is #f, the argument is a pathname string that is relative to the current directory. Otherwise, it is a path building on start-path. Consequently, supplying ([current-directory](#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29)) for start-path is different from supplying #f, because predicate receives complete paths in the former case and relative paths in the latter. Another difference is that predicate is not called for the current directory when start-path is #f.
If skip-filtered-directory? is true, then when predicate returns #f for a directory, the directory’s content is not traversed.
If follow-links? is true, the [find-files](#%28def._%28%28lib._racket%2Ffile..rkt%29._find-files%29%29) traversal follows links, and links are not included in the result. If follow-links? is #f, then links are not followed, and links are included in the result.
If start-path does not refer to an existing file or directory, then predicate will be called exactly once with start-path as the argument.
The [find-files](#%28def._%28%28lib._racket%2Ffile..rkt%29._find-files%29%29) procedure raises an exception if it encounters a directory for which [directory-list](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._directory-list%29%29) fails.
Changed in version 6.3.0.11 of package base: Added the #:skip-filtered-directory? argument.
> ```
(pathlist-closure path-list
   [ #:path-filter path-filter
    #:follow-links? follow-links?)


# 15.2 Filesystem
  →  (listof path?)
  path-list : (listof path-string?)
  path-filter : (or/c #f (path? .  →  . any/c)) = #f
  follow-links? : any/c = #f
```
Given a list of paths, either absolute or relative to the current directory, returns a list such that

-  if a nested path is given, all of its ancestors are also included in the result (but the same ancestor is not added twice);

-  if a path refers to directory, all of its descendants are also included in the result, except as omitted by path-filter;

-  ancestor directories appear before their descendants in the result list, as long as they are not misordered in the given path-list.

If path-filter is a procedure, then it is applied to each descendant of a directory. If path-filter returns #f, then the descendant (and any of its descendants, in the case of a subdirectory) are omitted from the result.

If follow-links? is true, then the traversal of directories and files follows links, and the link paths are not included in the result. If follow-links? is #f, then the result list includes paths to link and the links are not followed.

Changed in version 6.3.0.11 of package base: Added the #:path-filter argument.

> ```
(fold-files proc
    init-val
   [ start-path
    follow-links?)    →    any

   proc   :   ( or/c ( path? ( or/c ' file ' dir ' link ) any/c
> .  →  . any/c )
> ( path? ( or/c ' file ' dir ' link ) any/c
> .  →  . ( values any/c any/c ) ) )

  init-val : any/c
  start-path : (or/c path-string? #f) = #f
  follow-links? : any/c = #t```

Traverses the filesystem starting at start-path, calling proc on each discovered file, directory, and link. If start-path is #f, then the traversal starts from ([current-directory](#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29)).

The proc procedure is called with three arguments for each file, directory, or link:

-   If start-path is #f, the first argument is a pathname string that is relative to the current directory. Otherwise, the first argument is a pathname that starts with start-path. Consequently, supplying ([current-directory](#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29)) for start-path is different from supplying #f, because proc receives complete paths in the former case and relative paths in the latter. Another difference is that proc is not called for the current directory when start-path is #f.

-   The second argument is a symbol, either 'file, 'dir, or 'link. The second argument can be 'link when follow-links? is #f, in which case the filesystem traversal does not follow links. If follow-links? is #t, then proc will only get a 'link as a second argument when it encounters a dangling symbolic link (one that does not resolve to an existing file or directory).

-   The third argument is the accumulated result. For the first call to proc, the third argument is init-val. For the second call to proc (if any), the third argument is the result from the first call, and so on. The result of the last call to proc is the result of [fold-files](#%28def._%28%28lib._racket%2Ffile..rkt%29._fold-files%29%29).

The proc argument is used in an analogous way to the procedure argument of [foldl](pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29), where its result is used as the new accumulated result. There is an exception for the case of a directory (when the second argument is 'dir): in this case the procedure may return two values, the second indicating whether the recursive scan should include the given directory or not. If it returns a single value, the directory is scanned. In the cases of files or links (when the second argument is 'file or 'link), a second value is permitted but ignored.

If the start-path is provided but no such path exists, or if paths disappear during the scan, then an exception is raised.

> ```
(parameter)	→
```


# 15.2 Filesystem
(parameter)	→```
Creates the parent directory of the path specified by path, creating intermediate directories as necessary, and never failing if an ancestor of path exists already.
If path is a filesystem root or a relative path with a single path element, then no directory is created. Like [make-directory*](#%28def._%28%28lib._racket%2Ffile..rkt%29._make-directory%2A%29%29), if path is a relative path and the current directory does not exist, then [make-parent-directory*](#%28def._%28%28lib._racket%2Ffile..rkt%29._make-parent-directory%2A%29%29) will not create it.
Added in version 6.1.1.3 of package base.
> ```
(make-temporary-file [template
    #:copy-from copy-from
    #:base-dir base-dir
    compat-copy-from
    compat-base-dir)
  →  (and/c path? complete-path?)
  template : string? = "rkttmp~a"
  copy-from : (or/c path-string? #f 'directory) = #f
  base-dir : (or/c path-string? #f) = #f
   compat-copy-from   :   (or/c path-string? #f 'directory)
      =   copy-from
  compat-base-dir : (or/c path-string? #f) = base-dir


# 15.2 Filesystem
```
(current-directory)	→
(-> and/c path? complete-path?)```

Like [make-temporary-file](#%28def._%28%28lib._racket%2Ffile..rkt%29._make-temporary-file%29%29), but creates a directory, rather than a regular file.

As with [make-temporary-file](#%28def._%28%28lib._racket%2Ffile..rkt%29._make-temporary-file%29%29), if the template argument is not provided, a template string is generated from the source location of the call to [make-temporary-directory](#%28def._%28%28lib._racket%2Ffile..rkt%29._make-temporary-directory%29%29) when possible: the default is "rkttmp\~a" only when no source location information is available.

Added in version 8.4.0.3 of package base.

> ```
(make-temporary-file* prefix
    suffix
   [ #:copy-from copy-from
    #:base-dir base-dir)

  →  (and/c path? complete-path?)
  prefix : bytes?
  suffix : bytes?
  copy-from : (or/c path-string? #f) = #f
  base-dir : (or/c path-string? #f) = #f

(make-temporary-directory*   prefix
    suffix
   [ #:base-dir base-dir)

  →  (and/c path? complete-path?)
  prefix : bytes?
  suffix : bytes?
  base-dir : (or/c path-string? #f) = #f
```


# 15.2 Filesystem
Like make-temporary-file and make-temporary-directory, respectively, but, rather than using a template for format, the path is based on (bytes-append prefix generated suffix), where generated is a byte string chosen by the implementation to produce a unique path. If there is source location information for the callsite of make-temporary-file* or make-temporary-directory*, generated will incorporate that information. The resulting path is combined with base-dir as with make-temorary-file.
Added in version 8.4.0.3 of package base.
> ```
(call-with-atomic-output-file
    file
    proc
   [ #:security-guard security-guard
    #:rename-fail-handler rename-fail-handler)
   →   any
  file : path-string?
  proc : (output-port? path? .  →  . any)
  security-guard : (or/c #f security-guard?) = #f
   rename-fail-handler   :   (or/c #f (exn:fail:filesystem? path? .  →  . any))
      =   #f```
Opens a temporary file for writing in the same directory as file, calls proc to write to the temporary file, and then atomically (except on Windows) moves the temporary file in place of file. The move simply uses [rename-file-or-directory](#%28def._%28%28quote._~23~25kernel%29._rename-file-or-directory%29%29) on Unix and Mac OS, and it uses [rename-file-or-directory](#%28def._%28%28quote._~23~25kernel%29._rename-file-or-directory%29%29) on Windows if rename-fail-handler is provided; otherwise, on Windows, the moves uses an extra rename step (see below) on Windows to avoid problems due to concurrent readers of file.


# 15.2 Filesystem
The proc function is called with an output port for the temporary file, plus the path of the temporary file. The result of proc is the result of [call-with-atomic-output-file](#%28def._%28%28lib._racket%2Ffile..rkt%29._call-with-atomic-output-file%29%29).
The [call-with-atomic-output-file](#%28def._%28%28lib._racket%2Ffile..rkt%29._call-with-atomic-output-file%29%29) function arranges to delete temporary files on exceptions.
Windows prevents programs from deleting or replacing files that are open, but it allows renaming of open files. Therefore, on Windows, [call-with-atomic-output-file](#%28def._%28%28lib._racket%2Ffile..rkt%29._call-with-atomic-output-file%29%29) by default creates a second temporary file extra-tmp-file, renames file to extra-tmp-file, renames the temporary file written by proc to file, and finally deletes extra-tmp-file. Since that process is not atomic, however, [rename-file-or-directory](#%28def._%28%28quote._~23~25kernel%29._rename-file-or-directory%29%29) is used if rename-fail-handler is provided, where [rename-file-or-directory](#%28def._%28%28quote._~23~25kernel%29._rename-file-or-directory%29%29) has some chance of being atomic, since that the source and destination of the moves will be in the same directory; any filesystem exception while attempting to rename the file is send to rename-fail-handler, which can re-[raise](exns.html#%28def._%28%28quote._~23~25kernel%29._raise%29%29) the exception or simply return to try again, perhaps after a delay. In addition to a filesystem exception, the rename-fail-handler procedure also receives the temporary file path to be moved to path. The rename-fail-handler argument is used only on Windows.


# 15.2 Filesystem
Changed in version 7.1.0.6 of package base: Added the #:rename-fail-handler argument.
> ```
(parameter)	→
(-> any)
```
(weakly)	→
(-> the default)```

Installs a set of preference values and writes all current values to the preference file designated by ([find-system-path](#%28def._%28%28quote._~23~25kernel%29._find-system-path%29%29) 'pref-file), or filename if it is supplied and not #f.

The names argument supplies the preference names, and vals must have the same length as names. Each element of vals must be an instance of a built-in data type whose [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) output is [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29)able (i.e., the [print-unreadable](Writing.html#%28def._%28%28quote._~23~25kernel%29._print-unreadable%29%29) parameter is set to #f while writing preferences).

Current preference values are read from the preference file before updating, and a write lock is held starting before the file read, and lasting until after the preferences file is updated. The lock is implemented by the existence of a file in the same directory as the preference file; see [preferences-lock-file-mode](#%28def._%28%28lib._racket%2Ffile..rkt%29._preferences-lock-file-mode%29%29) for more information. If the directory of the preferences file does not already exist, it is created.

If the write lock is already held, then locked-proc is called with a single argument: the path of the lock file. The default locked-proc (used when the locked-proc argument is #f) reports an error; an alternative thunk might wait a while and try again, or give the user the choice to delete the lock file (in case a previous update attempt encountered disaster and locks are implemented by the presence of the lock file).

If filename is #f or not supplied, and the preference file does not already exist, then values read from the "defaults" collection (if any) are written for preferences that are not mentioned in names.

> ```
(preferences-lock-file-mode)  →  (or/c 'exists 'file-lock)
```


# 15.2 Filesystem
(parameter)	→
(-> path-string? . → . any)```
Creates a procedure suitable for use as the #:lock-there argument to [get-preference](#%28def._%28%28lib._racket%2Ffile..rkt%29._get-preference%29%29), where the name, failure-thunk, flush-mode, and filename are all passed on to [get-preference](#%28def._%28%28lib._racket%2Ffile..rkt%29._get-preference%29%29) by the result procedure to retry the preferences lookup.
Before calling [get-preference](#%28def._%28%28lib._racket%2Ffile..rkt%29._get-preference%29%29), the result procedure uses ([sleep](threads.html#%28def._%28%28quote._~23~25kernel%29._sleep%29%29) delay) to pause. Then, if ([*](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29) 2 delay) is less than max-delay, the result procedure calls [make-handle-get-preference-locked](#%28def._%28%28lib._racket%2Ffile..rkt%29._make-handle-get-preference-locked%29%29) to generate a new retry procedure to pass to [get-preference](#%28def._%28%28lib._racket%2Ffile..rkt%29._get-preference%29%29), but with a delay of ([*](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29) 2 delay). If ([*](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29) 2 delay) is not less than max-delay, then [get-preference](#%28def._%28%28lib._racket%2Ffile..rkt%29._get-preference%29%29) is called with the given lock-there, instead.
> ```
(call-with-file-lock/timeout filename
    kind
    thunk
    failure-thunk
   [ #:lock-file lock-file
    #:delay delay
    #:max-delay max-delay)    →    any