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 2 3730
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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.
|
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...
|
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
|
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\\..\\...
| |
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.
|
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
|
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...
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |