The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
C# Error: The specified path, file name, or both are too long
Discuss C# Error: The specified path, file name, or both are too long in the C Programming forum on Dev Shed. C# Error: The specified path, file name, or both are too long C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 7th, 2010, 09:17 PM
|
|
Participant
|
|
Join Date: Sep 2005
Location: Hawaii
|
|
|
C# Error: The specified path, file name, or both are too long
I have a C# Windows Form application that searches a file for a particular string. When it gets to files that are in directories that are too long it throws this error:
LOG Code:
Original
- LOG Code |
|
|
|
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.
Here is my function (simplified / psuedo), which called in a loop, reading a list of fully qualified file names:
C# Code:
Original
- C# Code |
|
|
|
public string scanFile(string filePath) { try { /****** ERROR IS THROWN LINE BELOW ******/ TextReader reader = new StreamReader(filePath); string line = ""; while ((line = reader.ReadLine()) != null) { .....do lots of stuff } if (yada yada) { return report; } else { return null; } } catch (Exception e) { throw e; } }
It is already a mapped drive, saving some characters, but it still is really long for some directories.
Ideas?
SK
|

September 7th, 2010, 11:15 PM
|
 |
Lord of Dorkness
|
|
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
|
|
|
Can't you temporarily SUBST a large portion of the path?
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.
|

September 8th, 2010, 09:20 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 27
  
Time spent in forums: 10 h 5 m 22 sec
Reputation Power: 0
|
|
Do you get the same problem when you use a System.IO.FileInfo object?
You can open the file stream from that object and accomplish the same thing you are trying to do.
Code:
FileInfo fi = new FileInfo(filePath);
TextReader tr = new StreamReader( fi.OpenRead()) as TextReader;
|

September 8th, 2010, 01:33 PM
|
|
Participant
|
|
Join Date: Sep 2005
Location: Hawaii
|
|
|
Thanks for the replies.
Not sure what you mean by SUBST, the path is a fixed string, eventually in the code it will have to resolve to the FQDN. Unless you have an example, I guess I don't understand what you mean, sorry.
As far as the FileInfo, I have not tried that, but I will, hopefully that works.
Thanks,
SK
|

November 15th, 2012, 10:04 AM
|
|
|
The maximum length for a path in Windows used to be 260 characters. Recent versions allow paths up to about but not necessarily exactly 32,767 characters.
I'm assuming that your app is throwing a PathTooLongException. So, with that said, I'm attaching a link to a detailed MSDN discussion on this issue.
Naming paths and file names
**EDIT**
Another link that might be of interest to you.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|