• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
OpenTechTips

OpenTechTips

Short and Concise Guides for IT Professionals

MENUMENU
  • HOME
  • ALL TOPICS
    • Active Directory
    • Exchange
    • InfoSec
    • Linux
    • Networking
    • Scripting
      • PowerShell
    • SSL
    • Virtualization
    • Web
    • Tools
  • ABOUT
  • SUBSCRIBE
Home » Dealing With SUPER LONG file path in Windows

Dealing With SUPER LONG file path in Windows

June 10, 2020 - by Zsolt Agoston - last edited on June 10, 2020

After abandoning the 8.3 file name limitation (pre-Win95 all files had a max name length of 8 characters, and a 3-char long extension), the Windows Win32 API allowed whole file paths to be as long as 260 characters long. However, in modern file systems that limit is often met and exceeded as users are nesting more and more folders into each other, causing very long file paths to form. Once it is reached, files operations (move, copy, rename) will throw an error message stating the file path is too long.

Dealing With SUPER LONG file path in Windows

Command line fix

To get around the issue we take advantage of the NTFS file system supporting 32,767-character long filepaths. To get around the Win32 API limitation we use the '\\?\' prefix, that can be used in front of either a local or a UNC path. This prefix tells the API to stop parsing the input string and send it as it is to the operating system. This way even the quote and double-quote characters are allowed in filenames, that cause issues when the file path is parsed. See examples:

ls -LiteralPath '\\?\C:\[Very long path]\test.txt ' -Recurse
ls -LiteralPath \\?\UNC\EDGE.alwayshotcafe.com\C$\[Very long path]\test.txt

Assign a drive letter to a path

If you stick with the good old CMD line, you can always shorten the path by assigning the path a drive letter. Use the 'net use' or 'subst' commands.

Example:

subst X: "C:\temp\CentOS\from\Community\Enterprise\Operating\System\is\a\Linux\distribution\that\provides\a\free\community-supported\computing\platform\functionally\compatible\with\its\upstream\source\Red\Hat\Enterprise\Linux\RHEL\In\January\2014\CentOS\the"

:: or use net use, that requires a UNC path as the input:

net use X: "\\localhost\C$\temp\CentOS\from\Community\Enterprise\Operating\System\is\a\Linux\distribution\that\provides\a\free\community-supported\computing\platform\functionally\compatible\with\its\upstream\source\Red\Hat\Enterprise\Linux\RHEL\In\January\2014\CentOS\the"
Dealing With SUPER LONG file path in Windows

Now you can copy, rename, move your files, folders as needed. When you finish don't forget to remove the drive mapping.

subst X: /d

:: or

net use X: /d

Registry Fix - for all Windows editions

To enable long filepath support, a simple Registry edit is needed. Add the LongPathsEnabled double word value to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem and make sure it's set to 1.

Dealing With SUPER LONG file path in Windows

Set Long Path support with Group Policies

Windows 10, 2016 and later Pro editions have a built-in GP object that accomplishes the same thing. You can find it under "Computer Configuration > Administrative Templates > System > Filesystem", called "Enable Win32 long paths". Set it to 'Enabled'

Dealing With SUPER LONG file path in Windows

Reader Interactions

Community Questions Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • Command line fix
  • Assign a drive letter to a path
  • Registry Fix – for all Windows editions
  • Set Long Path support with Group Policies

  • Terms of Use
  • Disclaimer
  • Privacy Policy