Join 3,572 readers in helping fund MetaFilter (Hide)


How to deal with file names that are too long
February 2, 2006 9:44 AM   Subscribe

Windows XP annoyance: I've managed to create some files with names that are too long. How can I rename them?

I can't open them, and I can't find a way to copy, move, or burn them. Usual methods of renaming files don't work (F2, right-click menu, Properties, Windows Explorer, etc.) I've tried shortening the path by renaming folders, but that didn't do it either. These are mp3 files, by the way.
posted by hydrophonic to Computers & Internet (23 answers total) 2 users marked this as a favorite
 
The two methods the drop into my mind both require using the command line interface and going old school on the problem. Are you comfortable using DOS commands?
posted by JigSawMan at 9:49 AM on February 2, 2006


Yes, I think, but it's been a while.
posted by hydrophonic at 9:54 AM on February 2, 2006


You should be able to do it DOSways, using the eight-character variant from the command line. The eight-character version is the first six characters, plus a tilde, plus a counting number, plus the extension.

An example: if you have two files called:

Thisisareallyreallyreallyreallyreallylongfilename.txt
Thisisanotherreallyreallyreallylongfilename.txt


Then the eight-character versions of the files would be

THISIS~1.TXT
THISIS~2.TXT


respectively.

So, from the command prompt, you can type:

C:\Music\LongFiles\>del THISIS~1.TXT

and the file will be deleted.
posted by DrJohnEvans at 9:55 AM on February 2, 2006


Oops, you want to rename them, not delete them. So:

C:\Whatever\Directory>rename THISIS~1.mp3 MyShortName.mp3

Also, changing directories in XP DOS with long filenames can be annoying. The Command Prompt will probably dump you in your user directory, so you'll be prompted with

C:\Documents and Settings\YourUserName>

To get into the "My Documents" directory, you can use the [Tab] key to autocomplete. Type cd My, hit the [Tab] key, and the command will AutoComplete to

C:\Documents and Settings\YourUserName>cd "My Documents"

Apologies if I'm going over something you already know.
posted by DrJohnEvans at 10:02 AM on February 2, 2006


That is what I was going to type. I was also going to say that the wildcard * character will work in the rename command.
posted by JigSawMan at 10:14 AM on February 2, 2006


rename doesn't seem to like filenames with spaces, even with my eight-character version (which still has a space). I get "The syntax of the command is incorrect." I can rename test files without spaces in the name. Using the wildcard * crashes the command prompt.
posted by hydrophonic at 10:38 AM on February 2, 2006


DrJohnEvans advice gets you almost all the way there, but you also need to encapsulate any Windows filename with spaces in double quotes for DOS to handle it:

example:

rename "long filenames suck.txt" long_filenames.txt


That should do it!
posted by tweak at 10:52 AM on February 2, 2006


Argh! "The filename or extension is too long."
posted by hydrophonic at 11:09 AM on February 2, 2006


Oh, and quotes don't work with eight-character versions that have spaces. Any way to fix that?
posted by hydrophonic at 11:10 AM on February 2, 2006


can you copy and paste what you are trying to do, along with error messages, into the thread?

Just right-click the DOS prompt and select copy.
posted by tweak at 11:18 AM on February 2, 2006


Have you tried a third-party renamer? I user Oscar's Renamer for mass file renames. I can't vouch for its' ability to fix too-long filenames, but it's worth a shot.
posted by SteveInMaine at 11:19 AM on February 2, 2006


and ballpark, how long, exactly, are these filenames?
posted by tweak at 11:19 AM on February 2, 2006


How did you create them without an error? That seems like a major OS bug, allowing you to create a file you can't use.
posted by teece at 11:19 AM on February 2, 2006


Oh, and quotes don't work with eight-character versions that have spaces. Any way to fix that?

Eight-character filenames aren't designed to have spaces, so if you have a space within the first six characters of your long filename, just remove it.

So the directory "My Documents" becomes MYDOCU~1.
posted by DrJohnEvans at 11:37 AM on February 2, 2006


That seems like a major OS bug, allowing you to create a file you can't use.

Indeed. The mind boggles.

hydrophonic, if Steve's program doesn't work, according to this discussion (if it's true), FreshUI should add contextual right click options that will let you move or copy the file without the 'long filename error.'

Might be worth a shot.
posted by tweak at 11:39 AM on February 2, 2006


The short filenames never have spaces. Use dir /X to find out what the short filenames are, then do what DrJohnEvans said.
posted by insomnus at 11:39 AM on February 2, 2006


can you copy and paste what you are trying to do, along with error messages, into the thread?

Ok, here's the closest I've gotten, edited for the relevant bits, error messages in bold:


C:\My Music (to sort)\111 needs some work\VA - Hum Kisise Kum Naheen>dir

Directory of C:\My Music (to sort)\111 needs some work\VA - Hum Kisise Kum Nahe
en

05/14/2004 08:04 PM 10,171,959 Hum Kisise Kum Naheen - 05 - Mohd. Radi &
Chorus-Kishore Kumar & Chorus-R.D. Burman-Asha Bhosle, Kishore Kumar & Chorus -
Chand Mera Dil-Ah Dil Kya Mahfil Hai-Tum Kya Jaano-Mil Gaya Ham Ko Saathi.mp3
1 File(s) 10,171,959 bytes
2 Dir(s) 14,356,246,528 bytes free

C:\My Music (to sort)\111 needs some work\VA - Hum Kisise Kum Naheen>rename "Hum
Kisise Kum Naheen - 05 - Mohd. Radi & Chorus-Kishore Kumar & Chorus-R.D. Burman
-Asha Bhosle, Kishore Kumar & Chorus - Chand Mera Dil-Ah Dil Kya Mahfil Hai-Tum
Kya Jaano-Mil Gaya Ham Ko Saathi.mp3" shorter.mp3
The filename or extension is too long.

C:\My Music (to sort)\111 needs some work\VA - Hum Kisise Kum Naheen>dir /X

Directory of C:\My Music (to sort)\111 needs some work\VA - Hum Kisise Kum Nahe
en

05/14/2004 08:04 PM 10,171,959 HUMKIS~3.MP3 Hum Kisise Kum Naheen - 05 -
Mohd. Radi & Chorus-Kishore Kumar & Chorus-R.D. Burman-Asha Bhosle, Kishore Kum
ar & Chorus - Chand Mera Dil-Ah Dil Kya Mahfil Hai-Tum Kya Jaano-Mil Gaya Ham Ko
Saathi.mp3
1 File(s) 10,171,959 bytes
2 Dir(s) 14,299,869,184 bytes free

C:\My Music (to sort)\111 needs some work\VA - Hum Kisise Kum Naheen>rename HUMKIS~3.MP3 shorter.mp3
The system cannot find the path specified.



Have you tried a third-party renamer?

I tried Rename-It. I'll try Oscar's and FreshUI as soon as I get a chance.

and ballpark, how long, exactly, are these filenames?

I counted 199 characters.

How did you create them without an error?


Ripped from CD with Windows Media Player or something like it. Automatically named the file from the ID3 tags.

Thanks for everyone's input!
I'm off to work soon, and I might not get a chance to try again until the weekend. I'll post any progress. It's academic at this point since I could just go out and buy the CD again. But it irks me so!
posted by hydrophonic at 12:01 PM on February 2, 2006


I'd try renaming the folder "111 needs some work" to "1", then renaming "My Music" to "m" and then trying to rename them. Right now,

"C:\My Music (to sort)\111 needs some work\VA - Hum Kisise Kum Naheen\Hum Kisise Kum Naheen - 05 - Mohd. Radi & Chorus-Kishore Kumar & Chorus-R.D. Burman -Asha Bhosle, Kishore Kumar & Chorus - Chand Mera Dil-Ah Dil Kya Mahfil Hai-Tum Kya Jaano-Mil Gaya Ham Ko Saathi.mp3"

is 269 characters, which is greater than the maximum path length of 255. Renaming the folders brings it to 235 characters.
posted by helios at 12:17 PM on February 2, 2006 [1 favorite]


And I know you said that you tried to rename the folders, but this really seems like the first step in resolving the problem (maybe combining it with the short name solution). Perhaps you tried it with a different file that had a longer filename..
posted by helios at 12:19 PM on February 2, 2006


This KB article lists 5 ways to solve the problem, it assumes you want to delete the file but the same things work for making a copy
http://support.microsoft.com/?kbid=320081
posted by Lanark at 12:25 PM on February 2, 2006


It worked!

Shortening the path then working in the command line interface did the trick. Unless I just didn't shorten the path enough the first time around.

Anyway, here's the result:

C:\M\1\Hum>dir /x

Directory of C:\M\1\Hum

05/14/2004 08:04 PM 10,171,959 HUMKIS~3.MP3 Hum Kisise Kum Naheen - 05 -
Mohd. Radi & Chorus-Kishore Kumar & Chorus-R.D. Burman-Asha Bhosle, Kishore Kum
ar & Chorus - Chand Mera Dil-Ah Dil Kya Mahfil Hai-Tum Kya Jaano-Mil Gaya Ham Ko
Saathi.mp3

C:\M\1\Hum>rename humkis~3.mp3 shorter.mp3

C:\M\1\Hum>dir

Directory of C:\M\1\Hum

05/14/2004 08:04 PM 10,171,959 shorter.mp3

posted by hydrophonic at 12:35 PM on February 2, 2006


In windows there are generally two versions of a great number of API functions - an ANSI version and a UNICODE version. In the case of the filesystem, if you use the ANSI version you are limited to PATH_MAX (260) characters, but if you use the UNICODE version of the API you can create filenames up to 32k characters in length. Thus it is entirely possible to create a file using a UNICODE program that is too long to delete using older programs that use the ANSI API.
posted by Rhomboid at 3:19 PM on February 2, 2006


I run into this issue fairly often, as I work at primary schools and regularly see files with bizarre names (the default names generated by Word can easily run a couple hundred characters, if the document launches straight into body text).

a-very-long-(over-200-characters-here)-name.doc

can easily be created in a user's home folder, because that's mapped to N: drive on their local workstation; as far as the workstation is concerned the full pathname is

N:\a-very-long-(over-200-characters-here)-name.doc

which squeaks in under the 255-byte restriction. But if I try to work with that file on the server, doing something like

E:
cd \data\home\students\until-end-2012\username
rename "a-very-long-(over-200-characters-here)-name.doc" shortname.doc

I get errors because the resulting full pathname is too long.

My standard fix is to map a temporary drive letter to the directory I'm working with:

subst T: .
T:
rename "a-very-long-(over-200-characters-here)-name.doc" shortname.doc
E:
subst T: /d

posted by flabdablet at 3:20 PM on February 2, 2006 [1 favorite]


« Older What countries are most likely...   |  Help me make a mix cd about pu... Newer »
This thread is closed to new comments.