473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

PathTooLongException 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
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 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.GetDirectories();

foreach(FileInfo fi in files)
{
try
{
if(fi.FullName.Length >
Convert.ToInt32(txtFileLengthCutoff.Text))
{
Debug.WriteLine("try file: " + fi.FullName);
longFiles.Add(fi.FullName); // this is the arraylist
}
}
catch (System.IO.PathTooLongException e)
{
Debug.WriteLine("catch file: " + fi.FullName);
// string temp = fi.DirectoryName;
// temp = fi.FullName;

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

Nov 16 '05 #1
2 3709
Justin,

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

You may want to explore the data captured in the PathTooLongException
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 PathTooLongException, 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
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...
11
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
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...
6
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: ...
6
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: ...
0
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...
27
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...
0
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...
5
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.