# File::getFileIdentifier() result depends on current directory on Windows

**URL:** https://forum.juce.com/t/file-getfileidentifier-result-depends-on-current-directory-on-windows/33050
**Category:** General JUCE discussion
**Created:** [April 25, 2019, 4:37pm UTC](https://forum.juce.com/t/file-getfileidentifier-result-depends-on-current-directory-on-windows/33050 "2019-04-25T16:37:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)
#### Post date: [April 25, 2019, 4:37pm UTC](https://forum.juce.com/t/file-getfileidentifier-result-depends-on-current-directory-on-windows/33050/1 "2019-04-25T16:37:43Z")

</div>

Sample code:

```auto
	File::findFileSystemRoots (roots);
	File f = roots[0];

	File::getSpecialLocation (File::userHomeDirectory).setAsCurrentWorkingDirectory();
	int64 n1 = f.getFileIdentifier();

	File::getSpecialLocation (File::userApplicationDataDirectory).setAsCurrentWorkingDirectory();
	int64 n2 = f.getFileIdentifier();

	jassert (n1 == n2);

```

Result:

```auto
		n1	15481123719386479	__int64
		n2	3377699721030766	__int64

```

Project: [https://github.com/FigBug/juce\_bugs/blob/master/FileIDs/Source/Main.cpp](https://github.com/FigBug/juce_bugs/blob/master/FileIDs/Source/Main.cpp)

---

<div class="post-metadata">

### Author: ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)
#### Post date: [April 25, 2019, 4:43pm UTC](https://forum.juce.com/t/file-getfileidentifier-result-depends-on-current-directory-on-windows/33050/2 "2019-04-25T16:43:31Z")

</div>

Fixed code:

```auto
uint64 File::getFileIdentifier() const
{
    uint64 result = 0;

	String path = getFullPathName();
	if (path.endsWith (":"))
		path += "\\";

    auto h = CreateFile (path.toWideCharPointer(),
                         GENERIC_READ, FILE_SHARE_READ, nullptr,
                         OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);

    if (h != INVALID_HANDLE_VALUE)
    {
        BY_HANDLE_FILE_INFORMATION info;
        zerostruct (info);

        if (GetFileInformationByHandle (h, &info))
            result = (((uint64) info.nFileIndexHigh) << 32) | info.nFileIndexLow;

        CloseHandle (h);
    }

    return result;
}

```

---

<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: [April 29, 2019, 10:09am UTC](https://forum.juce.com/t/file-getfileidentifier-result-depends-on-current-directory-on-windows/33050/3 "2019-04-29T10:09:33Z")

</div>

Thank you for reporting.

> <https://github.com/WeAreROLI/JUCE/commit/8eb626a338558c341e5093ad73e96aa4e1ffebfb>
