20

I'm trying to properly name MP3s and I hit some arbitrary length of 129 characters (not 128?). NTFS supports 255 characters in file names, how do I fix this?

Star Wars - 6 - Return of the Jedi - 2 - 07 - Battle of Endor 2, Leia Is Wounded, The Duel Begins, Overtaking Bunker, Dark Si.mp3

2
  • 2
    It is better not to rely on really long filenames as this can lead to a number of problems. MP3s can have embedded metadata in the form of ID3 tags for this and/or use directories.
    – JamesRyan
    Commented Sep 14, 2014 at 11:01
  • 3
    I open files and playlists; I do not use "media libraries". My collections are properly named, I don't have any "1.mp3" files and can't stand people too lazy to properly name files; which "1.mp3" when every album has at least one track. ಠ_ಠ
    – John
    Commented Sep 14, 2014 at 11:12

4 Answers 4

12

It is possible that you are exceeding a total of 260 characters for the entire pathname, including the backslash characters.

How many characters are in the path, including the name of the mp3 file?

4
  • 1
    Yeah, turns out renaming the files on the drive without directories allows longer names. Pretty lame that the file name and paths are counted together and not separate.
    – John
    Commented Sep 13, 2014 at 4:34
  • 5
    the MAX_PATH constant is defined to be 260, not 256
    – phuclv
    Commented Sep 13, 2014 at 4:43
  • 1
    Folders though, have only a max of "247 char + <null>". See stackoverflow.com/a/15971467/632951
    – Pacerier
    Commented Aug 18, 2015 at 6:16
  • You are incorrect re maximum size of a path. It is less than you think. See pastebin.com/raw/Xcg7Wndc and C:\t>md "a_243char_ijbcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabhcdefghijabcdefghijabcdefghbijabccdghij_243char_hi" <-- The filename or extension is too long.
    – barlop
    Commented Apr 29, 2020 at 8:26
37

In Windows the default total path length must not exceed 260 characters (drive + :\ + 255 characters of filename + null terminator + probably for final \ in case the path is a directory or simply for even rounding). It was a relic from DOS's 8.3-name era where a 260-character path is a really deep path.

It's possible that your path to the folder was already very long, so the remaining part for your filename is just 129. If you want longer path, you have several solutions:

Since Windows 10 there's another option by removing MAX_PATH limitation§. You can enable it by setting HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled in registry or set Computer Configuration > Administrative Templates > System > Filesystem > Enable NTFS long paths in group policy

Note that folders have a different limit. If you make a new folder in PowerShell or .NET that has very long name you'll get the below error

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

That's because it "allows for 248 characters for the path plus the filename which allows for 12 characters."

MAX_PATH, which limits file paths to a paltry 259 characters (sans the terminating null); the current directory to 258 characters (sans a trailing backslash and null); and the path of a new directory to 247 characters (subtract 12 from 259 to leave space for an 8.3 filename).

The maximum length of the path of a file: 259 or 258 characters?


Read more:

The maximum path of 32,767 characters is approximate, because the \\?\ prefix may be expanded to a longer string by the system at run time, and this expansion applies to the total length.

§Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.

9
  • Thanks, David posted first and it worked, but you included resources so +1.
    – John
    Commented Sep 13, 2014 at 4:40
  • 1
    A similar solution is to use a junction. Check out schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html
    – Urhixidur
    Commented Sep 13, 2014 at 11:54
  • 1
    I'd rather use this answer, too. That way, you can keep your files where you want, and still be able to name them the way you'd like to. Plus, when you copy them to your device, it's most likely not going to care about the silly Windows limitation, as they have a very flat file hierarchy, and may not even use the file name directly (e.g. iPhone/iPad/iEtc uses hex characters for file names, and cross-references an index file).
    – phyrfox
    Commented Sep 13, 2014 at 23:43
  • The maximum number of characters for a filename is 255 characters, not 256
    – Edd
    Commented Jun 17, 2015 at 14:58
  • @Edd 255 characters + null termination
    – phuclv
    Commented Jun 17, 2015 at 16:14
0

If you need to copy the files with long paths. robocopy does a great job.

2
  • I'm not sure OP needs to copy file, they want to name the file. Do you think robocopy can handle name longer than 255/260?
    – Vylix
    Commented Feb 9, 2022 at 8:46
  • Yes I've moved thousands of files & folders with long attached emails saved in them where xcopy constantly failed saying "please reduce filename size" for some reason you can make these long folders & files no problem, one interesting example try to open a pdf from a long path & it will error , but chrome will open it Commented Feb 18, 2022 at 8:58
-1

Windows 7 will allow you to save filenames longer than 256 characters including path names and they can be accessed easily as well. The only small difficulty you may run into is when you copy them from one place to another, but you will be presented with a popup that asks you if you want to change the filename, not copy the file, or save it as is. I always save it as is and I've never had any problems. I've probably got a couple of hundred filenames that exceed the limit.

2
  • no, it won't allow you to save files longer than 255 characters since that's the file system limit
    – phuclv
    Commented Aug 20, 2018 at 0:34
  • the path, however, can be slightly longer (or much longer after removing MAX_PATH limitation)
    – phuclv
    Commented May 29, 2019 at 1:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .