# False positive in File::isAbsolutePath() on Windows

**URL:** <https://forum.juce.com/t/false-positive-in-file-isabsolutepath-on-windows/69753>\
**Category:** Windows\
**Created:** [October 20, 2026, 8:54am UTC](https://forum.juce.com/t/false-positive-in-file-isabsolutepath-on-windows/69753 "2026-10-20T08:54:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [October 20, 2026, 8:54am UTC](https://forum.juce.com/t/false-positive-in-file-isabsolutepath-on-windows/69753/1 "2026-10-20T08:54:09Z")

</div>

Consider this line:

`const auto file = juce::File::getCurrentWorkingDirectory().getChildFile ("\\hello.txt");`

The intent is to create a path to a file named “hello.txt” at the root of whatever drive (“C:”, “D:”) the current working directory is on.

The problem is that on Windows, the above code results in an assertion in File constructor, because:

1. getChildFile() checks if its argument is an absolute path with isAbsolutePath()
2. isAbsolutePath() sees a directory separator at the beginning of the path, and returns **true**
3. getChildFile() then proceeds to interpret the argument as an absolute path, constructing a File() with it
4. The called File() constructor hits the assertion, where it is explained that the passed argument is not an absolute path as it should have, and to resolve the issue suggests exactly the code that caused the assertion.

> When you supply a raw string to the File object constructor, it must be an absolute path.  
> If you’re trying to parse a string that may be either a relative path or an absolute path,  
> you MUST provide a context against which the partial path can be evaluated - you can do  
> this by simply using File::getChildFile() instead of the File constructor. E.g. saying  
> “**File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)**” would return an absolute  
> path if that’s what was supplied, or would evaluate a partial path relative to the CWD.

The problem IMHO is that, at step #2 above, isAbsolutePath() should have returned **false** for “\hello.txt”, because on Windows that’s a relative path: it lacks the drive letter.

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [October 29, 2026, 10:35am UTC](https://forum.juce.com/t/false-positive-in-file-isabsolutepath-on-windows/69753/2 "2026-10-29T10:35:13Z")

</div>

TL;DR:

`File::isAbsolutePath ("\hello.txt");`

returns true on Windows, but it shouldn’t.

“\hello.txt” is not an absolute path on that platform, it lacks the drive letter.

In fact, creating a File like this:

`File helloFile ("\hello.txt");`

triggers an assertion, complaining that the passed path is not absolute.

Can please the JUCE team give feedback about this?

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [October 29, 2026, 9:47pm UTC](https://forum.juce.com/t/false-positive-in-file-isabsolutepath-on-windows/69753/3 "2026-10-29T21:47:37Z")

</div>

Thank you for reporting.

We have made some changes here:

> <https://github.com/juce-framework/JUCE/commit/657712be233b3514a97005505f9f7f425c26db92>
>
> A path with a single leading separator but no drive or share, such as
> "\\foo.txt"…, was treated as absolute and handed to the File constructor, which
> asserted and resolved it against the current working directory's drive.
> getChildFile now resolves such paths against the drive or UNC share of the
> file it is called on.
> 
> File::isAbsolutePath also accepts a leading forward slash on Windows, matching
> the separator handling elsewhere in File, which makes the equivalent check in
> juce\_build\_tools redundant.
