# Requiring a file that is in a directory containing a dot

**URL:** <https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [July 30, 2024, 3:24pm UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062 "2024-07-30T15:24:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nik](https://racket.discourse.group/u/nik)\
**Post date:** [July 30, 2024, 3:24pm UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/1 "2024-07-30T15:24:56Z")

</div>

I was trying to require a file that is inside a directory via a relative path. Surprisingly, this did not work, but resulted in an error. For example, I have the file `dir.dot/x.rkt` (the content does not matter). When typing `(require "dir.dot/x.rkt")`, I get the following error:

```scheme
string:1:9: require: bad module-path string
  at: "dir.dot/x.rkt"
  in: (require "dir.dot/x.rkt")
 [,bt for context]

```

If I change into the directory and require the file it works. I would not have expected this behavior; is there a reason for this?

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [July 30, 2024, 4:44pm UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/2 "2024-07-30T16:44:00Z")

</div>

Hi, @nik.

Interesting. First time coming across this. A quick scan of [the docs](https://docs.racket-lang.org/reference/require.html) would have me believe that `(file ...)` is what you might be looking for.

As an example, I have `top/path/requiring-file.rkt` and then `top/some.dir/some-file.rkt`.

The requiring file can reference the `some-file.rkt` just fine using this:

```scheme
(require (file "../some.dir/some-file.rkt"))

```

I am on Windows 11 for this test, if that makes any difference.

I hope that helps.

---

<div class="post-metadata">

**Author:** ![nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nik](https://racket.discourse.group/u/nik)\
**Post date:** [July 31, 2024, 8:13am UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/3 "2024-07-31T08:13:04Z")

</div>

Yes, that seems to do the trick; thank you. I'm a bit surprised that this other option exists as I don't really understand why the two cases are treated differently. (And the docs only mention the user expansion.)

---

<div class="post-metadata">

**Author:** ![usao](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/usao/32/1375_2.png) [@usao](https://racket.discourse.group/u/usao)\
**Post date:** [July 31, 2024, 9:49am UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/4 "2024-07-31T09:49:14Z")

</div>

The restriction is documented under [the `rel-string` section for module paths](https://docs.racket-lang.org/reference/require.html).

> The path cannot be empty or contain a leading or trailing slash, _path elements before than [sic] the last one cannot include a file suffix (i.e., a `.` in an element other than `.` or `..`)_, and the only allowed characters are ASCII letters, ASCII digits, `-`, `+`, `_`, `.`, `/`, and `%` (emphasis mine).

The reason may be historical.

---

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [August 1, 2024, 4:15am UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/5 "2024-08-01T04:15:58Z")

</div>

Not relevant to the specific question you're asking, but related:

When using relative filepaths, [define-runtime-path](https://docs.racket-lang.org/reference/Filesystem.html#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29) is a big help. It constructs an absolute path from a relative path starting from the current file so that you don't need to worry about what the current directory is at any given moment:

```scheme
#lang racket

(require racket/runtime-path)

(define-runtime-path here ".") ;; 'here' is relative to this file                                   

(println (build-path "." "foo"))
(println (build-path here "foo"))

```

Output on my machine:

```scheme
#<path:./foo>
#<path:/Users/dstorrs/projects/racket-pkgs/sudoku-maker/./foo>

```

(`define-runtime-path` is used for application code, not for a `require` line.)

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [August 1, 2024, 3:33pm UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/6 "2024-08-01T15:33:21Z")

</div>

This is speculation rather than an answer, but I wouldn't be surprised to discover that this could be a problem (or perhaps "bad interaction") with the way that file extensions are handled on certain platforms, possibly including Windows.

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [August 1, 2024, 3:45pm UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/7 "2024-08-01T15:45:11Z")

</div>

I'd be slightly leery of using define-runtime-path to require racket files; it seems probable to me that you'd be disrupting the ability of packages to overlap on collections.

---

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [August 1, 2024, 4:33pm UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/8 "2024-08-01T16:33:20Z")

</div>

> [@jbclements](#):
>
> I'd be slightly leery of using define-runtime-path to require racket files; it seems probable to me that you'd be disrupting the ability of packages to overlap on collections.

That is an excellent point. I'm glad you pointed it out. 😛

> [@dstorrs](#):
>
> (`define-runtime-path` is used for application code, not for a `require` line.)

---

<div class="post-metadata">

**Author:** ![robby](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/robby/32/7_2.png) [@robby](https://racket.discourse.group/u/robby)\
**Post date:** [August 1, 2024, 5:12pm UTC](https://racket.discourse.group/t/requiring-a-file-that-is-in-a-directory-containing-a-dot/3062/9 "2024-08-01T17:12:26Z")

</div>

If you want to use the require-based resolution but get access to a path in a way to declares a dependency, you can use something like this:

```scheme
(define-runtime-path racket/list.rkt '(lib "list.rkt" "racket"))

```

There's also a variant for dynamic-libraries (that I have no real experience with, tho).
