msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

limit on the length of PathName When using Dir in VB6

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions
Author Message
n777krish



Joined: 04 Oct 2007
Posts: 3

PostPosted: Tue May 01, 2007 7:58 pm    Post subject: limit on the length of PathName When using Dir in VB6 Reply with quote

Hello All,

I am using the Dir function in VB6 and seem to have encountered an
upper limit on the length of the PathName passed into the Dir
function.

When I have a Path longer than 260 (inclusive) characters then using
Dir generates the following error.

[Microsoft Visual Basic]
------------------------------------
Run-time error '53':

File not found
------------------------------------

Notes:
1. Yes I have verified that the file already exists at the path.
2. If I decrease the filepath length to 259 chracters then this works
fine. If I change it to 260 char. this error is generated.

Questions:
1.Could someone confirm this upper limit as I couldn't find any
indication of this on Microsofts site?
2. Any advise on an alternative to using Dir?

Thank you very much for any insight into the problem.

Neil Goundar.

Some test code:
In VB i have the following as a test (in the immediate window):
?len(dir("C:\Neil's Work Email In HTML\March 2007 Email\March Inbox
Items\test rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrruhsadfhdasldhasfjhgjasdgh
Test Test Test Test TestTest Test Test Test TestTest Test Test Test
TestTest Test Test Test TestTest Test Test Test Tes\yutruyfgdsuyf uy
fufauefguywfuysdfuyfdsuayf uysafd uyfdsa uyfuysfd uyfdsa uyf dsuy fduy
fdsuyasdfuysdf uyfsaduyfduay.txt"))

Archived from group: microsoft>public>vb>general>discussion
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Tue May 01, 2007 8:14 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

wrote in message @u30g2000hsc.googlegroups.com...
> Hello All,
>
> I am using the Dir function in VB6 and seem to have encountered an
> upper limit on the length of the PathName passed into the Dir
> function.
>
> When I have a Path longer than 260 (inclusive) characters then using
> Dir generates the following error.
>
> [Microsoft Visual Basic]
> ------------------------------------
> Run-time error '53':
>
> File not found
> ------------------------------------
>
> Notes:
> 1. Yes I have verified that the file already exists at the path.
> 2. If I decrease the filepath length to 259 chracters then this works
> fine. If I change it to 260 char. this error is generated.
>
> Questions:
> 1.Could someone confirm this upper limit as I couldn't find any
> indication of this on Microsofts site?

Yes, 260 is the max path length in windows

> 2. Any advise on an alternative to using Dir?

use short names
Back to top
View user's profile Send private message
n777krish



Joined: 04 Oct 2007
Posts: 3

PostPosted: Tue May 01, 2007 8:43 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

Hi Bob,

Thanks for the information. I really appreciate it.

The problem is that a customer has a really massive folder structure
(folders inside folders inside folders ... ) and it is not possible
for me to ask him to change the folder structure.

A possibility would be to move into the folder and then check if the
file exists in there. Would you say that this may work?

>From theory at least I can see this giving me headaches if the file
name is really long Sad

Thanks,
Neil.

On May 2, 11:14 am, "Bob Butler" wrote:
> wrote in message
>
> @u30g2000hsc.googlegroups.com...
>
>
>
>
>
> > Hello All,
>
> > I am using theDirfunction in VB6 and seem to have encountered an
> > upper limit on the length of the PathName passed into theDir
> > function.
>
> > When I have a Path longer than 260 (inclusive) characters then using
> >Dirgenerates the following error.
>
> > [Microsoft Visual Basic]
> > ------------------------------------
> > Run-time error '53':
>
> > File not found
> > ------------------------------------
>

> > Notes:
> > 1. Yes I have verified that the file already exists at the path.
> > 2. If I decrease the filepath length to 259 chracters then this works
> > fine. If I change it to 260 char. this error is generated.
>
> > Questions:
> > 1.Could someone confirm this upper limit as I couldn't find any
> > indication of this on Microsofts site?
>
> Yes, 260 is the max path length in windows
>
> > 2. Any advise on an alternative to usingDir?
>
> use short names- Hide quoted text -
>
> - Show quoted text -
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Tue May 01, 2007 9:02 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

wrote in message @p77g2000hsh.googlegroups.com...
> Hi Bob,
>
> Thanks for the information. I really appreciate it.
>
> The problem is that a customer has a really massive folder structure
> (folders inside folders inside folders ... ) and it is not possible
> for me to ask him to change the folder structure.
>
> A possibility would be to move into the folder and then check if the
> file exists in there. Would you say that this may work?
>


worth a try; I'd certainly mention him the customer that it could cause
problems.
Back to top
View user's profile Send private message
n777krish



Joined: 04 Oct 2007
Posts: 3

PostPosted: Tue May 01, 2007 9:11 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

Thanks Bob for your help. I really appreciate it.

Yes, I probably will need to do that.

I found out some interesting things today though that I cannot even
create a folder inside a folder if the max length is reached.

Probably will need to advice him to upgrade to 64 bit machine to get
around this Smile ... just kidding ...

Thanks,
Neil Goundar.
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Wed May 02, 2007 1:36 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

n777krish@gmail.com wrote:
>>> Questions:
>>> 1.Could someone confirm this upper limit as I couldn't find any
>>> indication of this on Microsofts site?
>>
>> Yes, 260 is the max path length in windows
>
> The problem is that a customer has a really massive folder structure
> (folders inside folders inside folders ... ) and it is not possible
> for me to ask him to change the folder structure.

MAX_PATH is 260 for ANSI names. Unicode names can be 32K chars. The catch is,
you'll need to go totally API to use them. See docs for FindFirstFile:

"In the ANSI version of this function, the name is limited to MAX_PATH CHARs. To
extend this limit to 32,767 wide characters, call the Unicode version of the
function and prepend "\\?\" to the path."
http://msdn2.microsoft.com/en-us/library/aa364418.aspx

Also, "Naming a File":

"In the Windows API, the maximum length for a path is MAX_PATH, which is defined
as 260 characters. A path is structured in the following order: drive letter, colon,
backslash, components separated by backslashes, and a null-terminating character,
for example, the maximum path on the D drive is D:\NUL.
"The Unicode versions of several functions permit a maximum path length of
approximately 32,000 characters composed of components up to 255 characters in
length. To specify that kind of path, use the "\\?\" prefix."
http://msdn2.microsoft.com/en-us/library/aa365247.aspx

Later... Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Wed May 02, 2007 2:10 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

"Karl E. Peterson" wrote in message @TK2MSFTNGP05.phx.gbl...
> MAX_PATH is 260 for ANSI names. Unicode names can be 32K chars.

I hadn't realized that you could get around it using the W versions
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Wed May 02, 2007 4:03 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

Bob Butler wrote:
> "Karl E. Peterson" wrote in message
> @TK2MSFTNGP05.phx.gbl...
>> MAX_PATH is 260 for ANSI names. Unicode names can be 32K chars.
>
> I hadn't realized that you could get around it using the W versions

I've never actually tried. My fear was that doing so would only serve to break
other things. "Slippery slope" was the term that came to mind...
--
..NET: It's About Trust!
http://vfred.mvps.org
Back to top
View user's profile Send private message
Tony Proctor



Joined: 04 Oct 2007
Posts: 1051

PostPosted: Thu May 03, 2007 11:54 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

Since the \\?\ prefix can be used on any Windows path name, I'd give it a
try in the VB Dir function. I know it accepts it - I just haven't tried it
with a path name quite that long Smile

Tony Proctor

"Bob Butler" wrote in message@TK2MSFTNGP05.phx.gbl...
> "Karl E. Peterson" wrote in message
> @TK2MSFTNGP05.phx.gbl...
> > MAX_PATH is 260 for ANSI names. Unicode names can be 32K chars.
>
> I hadn't realized that you could get around it using the W versions
>
Back to top
View user's profile Send private message
Walter Dow



Joined: 26 Feb 2008
Posts: 1

PostPosted: Tue Feb 26, 2008 4:27 pm    Post subject: Re: limit on the length of PathName When using Dir in VB6 Reply with quote

The easies way is using some libraries like that supports long paths
like http://www.abtollc.com/product1733992.html

There is no need to rename files or perform any other actions, it just
allows to work with files keeping their real long paths, thats all.

Walter


*** Sent via Developersdex http://www.developersdex.com ***

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Limit on number of Modules/forms? Hi, I am using VB6 SP6. Within the ide, I have about 863 forms and modules. Now when I try to add another form or module, I get the out of memory error and it does not allow me to add more files to the project. I know for fact that I have plenty memor

Get the length of a string Hi, How can I get the length of a string (in characters) ? I tried using "Len" function, but in japanese text I get: Len = (characters number)*2 + 1 Yoav.

Limit number of char's keyed into a text box? How can I limit the number of characters that can be entered in to a textbox? I have a situation where I want to allow no more than 4 characters to be entered. I don't want to go through the hassle (for both me and the user) of bringing up a message box a

How to limit the coloumns in a listview to the header text hello, I'm Trying to limit the columns in a listview to the header text. Is there an easy way of doing this. Perhaps using API ? Greetings, Farmer

FileSystemObject folder length Hello, I am wondering if there is a limit on how long a folder path can be for the I am trying to copy a file into a folder structure. and getting an error. my path is longer than 256 chars. and this seems to be the problem. the path i
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group