filename length in XP

  • Thread starter Thread starter pjohnst0n
  • Start date Start date
P

pjohnst0n

hi,

can anyone tell me the max length you can have for filename in XP?
(incl. path)

cheers
 
PJohns,

255 + 1. The 1 = NULL teminating character.

260 chars is the length when you are programming for the buffer size
 
The PATH counts also.

Here's some info.

File names in XP can have up to 255 characters.

Most PROGRAMS only recognize a PATH length of around 256 characters.

The path can only have 260 characters. A path is structured as follows:
drive letter, colon, backslash, components separated by backslashes, and a
null-terminating character. For example, the maximum path on the D drive is
D:\<256 chars>NUL.

[[Win32 programs are limited to a 256-character string size limit because of
the MAX_PATH variable. Software programs can work around this problem by
passing Win32 a path that is MAX_PATH or less. The real underlying path can
then be accessed independently of the real length of the path. In this way,
a program can access files or directories beyond MAX_PATH on the server. ]]
Path Too Long Error Message When Exceeding MAX_PATH
http://support.microsoft.com/kb/177665

I just named a txt file with this name...
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat.txt

That is the maximum number of characters that I could get, around 190.
Windows would not let me type any more characters.

This is the actual path to the file...
C:\Documents and Settings\Wesley P. Vogel\Desktop\New Folder(2)\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat.txt

190 characters in the name.
3 characters in the extension.
14 characters in New Folder (2)
15 characters in Wesley P. Vogel
22 characters in Documents and Settings
----------
About 244 characters total. It's possible that I may have miscounted.
Close enough for the girls that we go with. ;-)

I tried to drag that 190 character file to this folder...
C:\Documents and Settings\Wesley P. Vogel\My Documents\My Download
Files\Batch Files\advanced\DISK

This is the exact error message that I got...
---------------------------
Error Moving File or Folder
---------------------------
Cannot move
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat: The file name you specified is not
valid or too long.
Specify a different file name.
---------------------------
OK
---------------------------

When I went to delete New Folder (2), I got this error:

---------------------------
Confirm File Delete
---------------------------
The folder 'New Folder (2)' contains items whose name is too long for
the Recycle Bin.

Do you want to permanently delete it?
---------------------------
Yes Yes to All No Cancel
---------------------------

So I clicked on Cancel.
I opened New Folder (2).
I renamed that 190_character-named.txt file to at.txt.
I then was able to delete the New Folder (2).

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
From: "Wesley Vogel" <[email protected]>

| The PATH counts also.
|
| Here's some info.
|
| File names in XP can have up to 255 characters.
|
| Most PROGRAMS only recognize a PATH length of around 256 characters.
|
| The path can only have 260 characters. A path is structured as follows:
| drive letter, colon, backslash, components separated by backslashes, and a
| null-terminating character. For example, the maximum path on the D drive is
| D:\<256 chars>NUL.
|
| [[Win32 programs are limited to a 256-character string size limit because of
| the MAX_PATH variable. Software programs can work around this problem by
| passing Win32 a path that is MAX_PATH or less. The real underlying path can
| then be accessed independently of the real length of the path. In this way,
| a program can access files or directories beyond MAX_PATH on the server. ]]
| Path Too Long Error Message When Exceeding MAX_PATH
| http://support.microsoft.com/kb/177665
|
| I just named a txt file with this name...
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat.txt
|
| That is the maximum number of characters that I could get, around 190.
| Windows would not let me type any more characters.
|
| This is the actual path to the file...
| C:\Documents and Settings\Wesley P. Vogel\Desktop\New Folder(2)\
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat.txt
|
| 190 characters in the name.
| 3 characters in the extension.
| 14 characters in New Folder (2)
| 15 characters in Wesley P. Vogel
| 22 characters in Documents and Settings
| ----------
| About 244 characters total. It's possible that I may have miscounted.
| Close enough for the girls that we go with. ;-)
|
| I tried to drag that 190 character file to this folder...
| C:\Documents and Settings\Wesley P. Vogel\My Documents\My Download
| Files\Batch Files\advanced\DISK
|
| This is the exact error message that I got...
| ---------------------------
| Error Moving File or Folder
| ---------------------------
| Cannot move
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat: The file name you specified is not
| valid or too long.
| Specify a different file name.
| ---------------------------
| OK
| ---------------------------
|
| When I went to delete New Folder (2), I got this error:
|
| ---------------------------
| Confirm File Delete
| ---------------------------
| The folder 'New Folder (2)' contains items whose name is too long for
| the Recycle Bin.
|
| Do you want to permanently delete it?
| ---------------------------
| Yes Yes to All No Cancel
| ---------------------------
|
| So I clicked on Cancel.
| I opened New Folder (2).
| I renamed that 190_character-named.txt file to at.txt.
| I then was able to delete the New Folder (2).
|

A way to get around the problem is to use the SUBST.EXE command such as...

subst P: "C:\Documents and Settings\Wesley P. Vogel\Desktop\New Folder(2)"

Thus you can manipulate the long file named file in "P:" because its path has been
effectively been shortened.
 
Thanks for the tip, but I only tried that once and kept the notes because I
was curious. ;-) I don't really have any need for filename that long.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
David H. Lipman said:
From: "Wesley Vogel said:
The PATH counts also.

Here's some info.

File names in XP can have up to 255 characters.

Most PROGRAMS only recognize a PATH length of around 256 characters.

The path can only have 260 characters. A path is structured as follows:
drive letter, colon, backslash, components separated by backslashes, and
a null-terminating character. For example, the maximum path on the D
drive is D:\<256 chars>NUL.

[[Win32 programs are limited to a 256-character string size limit
because of the MAX_PATH variable. Software programs can work around this
problem by passing Win32 a path that is MAX_PATH or less. The real
underlying path can then be accessed independently of the real length of
the path. In this way, a program can access files or directories beyond
MAX_PATH on the server. ]] Path Too Long Error Message When Exceeding
MAX_PATH http://support.microsoft.com/kb/177665

I just named a txt file with this name...
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat.txt

That is the maximum number of characters that I could get, around 190.
Windows would not let me type any more characters.

This is the actual path to the file...
C:\Documents and Settings\Wesley P. Vogel\Desktop\New Folder(2)\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat.txt

190 characters in the name.
3 characters in the extension.
14 characters in New Folder (2)
15 characters in Wesley P. Vogel
22 characters in Documents and Settings
----------
About 244 characters total. It's possible that I may have miscounted.
Close enough for the girls that we go with. ;-)

I tried to drag that 190 character file to this folder...
C:\Documents and Settings\Wesley P. Vogel\My Documents\My Download
Files\Batch Files\advanced\DISK

This is the exact error message that I got...
---------------------------
Error Moving File or Folder
---------------------------
Cannot move
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat: The file name you specified is
not valid or too long.
Specify a different file name.
---------------------------
OK
---------------------------

When I went to delete New Folder (2), I got this error:

---------------------------
Confirm File Delete
---------------------------
The folder 'New Folder (2)' contains items whose name is too long for
the Recycle Bin.

Do you want to permanently delete it?
---------------------------
Yes Yes to All No Cancel
---------------------------

So I clicked on Cancel.
I opened New Folder (2).
I renamed that 190_character-named.txt file to at.txt.
I then was able to delete the New Folder (2).

A way to get around the problem is to use the SUBST.EXE command such as...

subst P: "C:\Documents and Settings\Wesley P. Vogel\Desktop\New
Folder(2)"

Thus you can manipulate the long file named file in "P:" because its path
has been effectively been shortened.
 
From: "Wesley Vogel" <[email protected]>

| Thanks for the tip, but I only tried that once and kept the notes because I
| was curious. ;-) I don't really have any need for filename that long.
|

I run into this every so often with my Domain users. They create long filenames in deep
folders with long names and they "dig them selves into a hole". Using the SUBST.EXE command
allows me or the user to substitute to some folder and then flatten the tree thus reducing
the total length. Otherwise the path they see is too long and they get errors trying to
manipulate the files.
 
From: "Wesley Vogel" <[email protected]>

| Thanks for the tip, but I only tried that once and kept the notes because I
| was curious. ;-) I don't really have any need for filename that long.
|

I run into this every so often with my Domain users. They create long filenames in deep
folders with long names and they "dig them selves into a hole". Using the SUBST.EXE command
allows me or the user to substitute to some folder and then flatten the tree thus reducing
the total length. Otherwise the path they see is too long and they get errors trying to
manipulate the files.

thanks to all who replied. 1st time user here and will definitely be
back for the awesome help, even on the simplest of topics :-)
 
Have you tried creating an LAFNF yet? Long A** FileName File, not a
technical term I just made it up.

You have to learn to burn and burn to learn. ;-)

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
I know you're a command line junky. :-D

But you can also....
Path Too Long

To work around this problem, reduce the length of the path to less than 256
characters.

In Windows Explorer, select the folder one level above the folder that
returns the error. Right-click the folder returning the error and then click
Rename. Rename the folder to reduce the number of characters used in the
folder name.

Rename the folder so that the target files that are deeper than the MAX_PATH
no longer exist. If you do this, start at the root folder (or any other
convenient place), and then rename folders so that they have shorter names.

Rename subfolders in the path to a file so that the total path or file name
is less than the max_path setting or 256 characters. Start with subfolders
that are closer to the root so that you are always working with less than
256 characters.

Also see...
Files exist in paths that are deeper than MAX_PATH characters
here for other options...
You cannot delete a file or a folder on an NTFS file system volume
http://support.microsoft.com/kb/320081

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
Nothing wrong with using the command line. Lots of stuff that you cannot do
with the GUI.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top