473,770 Members | 5,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PathTooLongExce ption problem/question

Hi. I'm writing a little c# program to list all the files in a
selected directory longer than a given size. The problem is that when
it finds a file that is too long for Windows, I get the
PathTooLongExce ption error. I try to handle the exception, but can't
do anything because, well, the file is too long. I can see what and
where the offending file is in the Locals window, so .NET can obviously
read the file path, but I can't write that to any variable. Any
suggestions? (And how certain files that are too long get there in the
first place is another question for another day...) Following is an
outline of my code:

* user selects a directory from a treeview
* code calls the AddFilesToList method which iterates through the files
in the chosen directory
* when files are longer than e.g. 100 characters the file name is
written to an arraylist
* the subfolders of the chosen directory are iterated through each
recursively calling AddFilesToList

And the AddFilesToList method. (For some reason the spaces at the
start of lines aren't coming out, so I hope this is worth something.)
private void AddFilesToList( DirectoryInfo dir)
{
FileInfo[] files = dir.GetFiles();
DirectoryInfo[] subdirs = dir.GetDirector ies();

foreach(FileInf o fi in files)
{
try
{
if(fi.FullName. Length >
Convert.ToInt32 (txtFileLengthC utoff.Text))
{
Debug.WriteLine ("try file: " + fi.FullName);
longFiles.Add(f i.FullName); // this is the arraylist
}
}
catch (System.IO.Path TooLongExceptio n e)
{
Debug.WriteLine ("catch file: " + fi.FullName);
// string temp = fi.DirectoryNam e;
// temp = fi.FullName;

longFiles.Add(f i.FullName);
}
}
foreach (DirectoryInfo di in subdirs)
{
AddFilesToList( di);
}
}
Thanks for any help,
Justin

Nov 16 '05 #1
2 3730
Justin,

http://blogs.msdn.com/brian_dewey/ar.../19/60263.aspx

You may want to explore the data captured in the PathTooLongExce ption
instance. There are several properties, including InnerMessage, that
may shed more light on what's going wrong.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
Thanks Chris. I had tried exploring the PathTooLongExce ption, but
didn't find anything useful. The e.Message gives the same message that
prints out, and the InnerException gives nothing because it's null. I
know the information exists somewhere because as I said, I can see the
offending file in the Locals window as I'm debugging the code. Thanks
for the reply.
Justin

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1308
by: Shakil Khan | last post by:
System.IO.PathTooLongException "The path is too long after being fully qualified. Make sure path is less than 260 characters" Can anyone help, How to resolve this issue? This exception is coming when I m trying to copy such problematic file i.e. whose path is greater than 260 characters. I have read on some forums that this issue can't be solved. But then how MS-Word or other applications are hadling it because you can easily insert...
11
1389
by: ASP newbie | last post by:
I cannot run my asp.net application in w2k server. But the program works fine under w2k professional. Can anyone tell me is there any difference in the settings? Many thanks.
4
3929
by: Justin | last post by:
Hi. I'm writing a little c# program to list all the files in a selected directory longer than a given size. The problem is that when it finds a file that is too long for Windows, I get the PathTooLongException error. I try to handle the exception, but can't do anything because, well, the file is too long. I can see what and where the offending file is in the Locals window, so .NET can obviously read the file path, but I can't write...
6
1557
by: Tom | last post by:
I have a problem, to which I have been unable to find a solution for days now, after checking numerous references (both in books and online). Perhaps someone here can help. Here's my problem: I'm trying to define a series of radio objects as a large array for a survey, like this: 1) Does this make sense? <input type="radio" name="question" value="Y"> Yes <input type="radio" name="question" value="N"> No
6
1838
by: shrishjain | last post by:
Hi All, I call Assembly.LoadFrom("C:\\MyDir\\MyAssembly.dll")- it works fine. However when I call the following, it fails: Assembly.LoadFrom("C:\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\ ...\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\ MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\...
0
495
by: Johan Delimon | last post by:
Hello, Ever got this 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. Since the .NET Framework does not support long filenames :-( I had to write a library that calls the WIN32 API and wraps those functions like System.IO.
27
5151
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
0
2121
by: mjheitland | last post by:
When I pass my directories recursively on a directory structure with paths 260 chars I get the following exception (see line marked with ***), although I am using only ShortPathNames through Win32API function:: 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. My short path names are < 255 characters, but...
5
3357
by: Gillard | last post by:
hi , i try to io.file.delete(startmenushortcut) i get PathTooLongException how to delete those dead links in my start menu please
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.