DEV Community

DiskBee(NTFS for Mac)
DiskBee(NTFS for Mac)

Posted on

NTFS Transfers from macOS: A Preflight for Windows File Names

NUL.txt looks ordinary in Finder. So does a folder named COM¹. A report whose name ends with a period attracts even less attention.

All three can become naming problems when a Mac-born directory tree is copied to an NTFS drive for use on Windows. The awkward part is timing: the source disk is readable, the destination may be writable, and the transfer can still stop only when it reaches one particular entry.

A writable mount is therefore only the first check. Before a large copy, it is worth asking whether the names themselves will make sense on the other side.

NTFS and Windows naming are not the same question

It is tempting to reduce this to “NTFS supports it” or “NTFS rejects it.” That skips a layer.

There is the on-disk file system, the driver creating the entry, and the Windows API or shell that will later open it. Microsoft’s file-naming documentation gives a useful conservative boundary for that last part. It lists reserved characters such as <, >, :, ", /, \, |, ?, and *, ASCII control characters 0–31, and device names including CON, PRN, AUX, NUL, COM1–COM9, and LPT1–LPT9. The superscript forms COM¹, COM², COM³, LPT¹, LPT², and LPT³ are reserved too.

The rule covers more than a file with no extension. Microsoft gives NUL.txt and NUL.tar.gz as equivalent to NUL for this purpose. It also says not to end a file or directory name with a space or period. The documentation makes an important distinction here: the underlying file system may support such a name while the Windows shell and user interface do not.

Check every path component, not just the final filename. A perfectly ordinary notes.txt inside a directory named AUX still has a problematic path.

A read-only preflight from macOS

This small Python checker walks a source tree without following directory symlinks. It applies the conservative rules above to the source folder, every subdirectory, and every file. It changes nothing on the source or destination.

Save it as check_ntfs_names.py:

#!/usr/bin/env python3
import os
import re
import sys

BAD_CHARS = re.compile(r'[<>:"/\\|?*\x00-\x1f]')
RESERVED = {
    "CON", "PRN", "AUX", "NUL",
    *(f"COM{i}" for i in "123456789¹²³"),
    *(f"LPT{i}" for i in "123456789¹²³"),
}


def problems(name):
    issues = []
    if BAD_CHARS.search(name):
        issues.append("reserved character or ASCII control character")
    if name.endswith((" ", ".")):
        issues.append("trailing space or period")
    base = name.split(".", 1)[0].rstrip(" .").upper()
    if base in RESERVED:
        issues.append("reserved Windows device name")
    return issues


def main():
    root = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else ".")
    failed = False

    def check(name, display_path):
        nonlocal failed
        issues = problems(name)
        if issues:
            failed = True
            print(f"{display_path!r}: {'; '.join(issues)}")

    check(os.path.basename(root), os.path.basename(root))

    def onerror(error):
        nonlocal failed
        failed = True
        print(f"{error.filename!r}: {error.strerror}", file=sys.stderr)

    for directory, subdirectories, files in os.walk(
        root, onerror=onerror, followlinks=False
    ):
        for name in subdirectories + files:
            path = os.path.join(directory, name)
            check(name, os.path.relpath(path, root))

    return int(failed)


if __name__ == "__main__":
    sys.exit(main())
Enter fullscreen mode Exit fullscreen mode

Run it against the folder you intend to copy:

python3 check_ntfs_names.py "$HOME/Desktop/Export"
Enter fullscreen mode Exit fullscreen mode

No output and exit status 0 mean that this particular check found nothing. Findings are printed with Python’s quoted representation, which makes an otherwise invisible trailing space visible. A finding or a directory read error produces exit status 1, so the same command can gate an export script.

I ran the checker on macOS against temporary folders containing clean and deliberately problematic names. This is the output from the problem fixture:

'COM¹': reserved Windows device name
'bad:name': reserved character or ASCII control character
'back\\slash': reserved character or ASCII control character
'report.': trailing space or period
'NUL.txt': reserved Windows device name
'trailing ': trailing space or period
Enter fullscreen mode Exit fullscreen mode

The clean fixture contained a nested normal.txt and returned 0 with no output. These tests exercised the scanner on local macOS folders; they were not presented as an NTFS write test.

One detail in the code is intentional: name.split(".", 1)[0] examines the text before the first period. That catches NUL.tar.gz, rather than checking only the last extension. The rstrip(" .") also makes the reserved-name check slightly conservative around unusual spacing. Renaming the offending entry is usually safer than trying to discover which Windows tool happens to tolerate it.

What a clean result does not prove

This is a naming preflight, not a transfer guarantee.

It does not detect two distinct source names that collide after case folding or Unicode normalization. Microsoft advises against assuming case sensitivity even though NTFS supports POSIX case-sensitive semantics in some configurations. A folder containing Readme and README deserves a separate collision check before it becomes input for a cross-platform workflow.

The script also does not calculate Windows path lengths, model alternate data streams, verify permissions on the destination, or establish that the NTFS volume is healthy and safely writable. A colon in a Mac filename is flagged because it is a reserved Win32 character; the checker does not attempt to reinterpret it as an alternate-data-stream expression. Free space, unplugging during a copy, and a volume left in a hibernated or otherwise unsafe state are different failure classes.

The name-length limit deserves the same restraint. Microsoft’s file-system comparison lists NTFS limits separately from application path behavior. Passing this short checker should not be read as proof that every Windows application can open a deeply nested result.

For a first real transfer, use a disposable destination directory and files you can recreate. Confirm the result on the Windows setup that matters, especially if the files will be consumed by an older application rather than Explorer alone.

The useful boundary is modest but practical: catch avoidable naming surprises before the copy starts, without pretending that a lexical check can validate the whole storage stack.

This post is from the DiskBee team. We build an FSKit-based NTFS and BitLocker utility for macOS. The checker above is independent of DiskBee and only reads the chosen source tree. Project site: https://www.ntfs.pro/

Top comments (0)