System.IO.PathTooLongException

  • Thread starter Thread starter Donald Xie
  • Start date Start date
D

Donald Xie

Hi,

The documentation states that this "exception that is
thrown when a pathname or filename is longer than the
system-defined maximum length". In my case, this max.
length is 260 characters on WinXP. Is there anyway to
change this value? If not, are there any workarounds?

Thanks,
Donald Xie
 
Hi,

The documentation states that this "exception that is
thrown when a pathname or filename is longer than the
system-defined maximum length". In my case, this max.
length is 260 characters on WinXP. Is there anyway to
change this value? If not, are there any workarounds?

Thanks,
Donald Xie

Isn't there a Path.GetShortFileName() or File.ShortName ?
that should do it
 
Hi Roy,

Thanks for replying. Sorry I should have given a bit more
details on what I was trying to do.

Yes there is a Path.GetFileName() that returns just the
name without directory path, but unfortunately it doesn't
do what I want. What I was trying to do is to take a
partial path to a file, e.g., testdir\testfile.txt (from
c:\myapp\testdir\testfile.txt), map it to another
directory (e.g., d:\mybackuproot\testdir\testfile.txt). If
the target directory doesn't exist, I will create it.

In my app, I use Path.Combine
(@"d:\mybackuproot", "testdir") to get the full path, then
Path.GetDirectory(fullpath) to check whether it exists and
if not, Path.CreateDirectory(fullpath) to create it. The
problem is that if the full path (which may be more than a
dozen directories deep) is longer than 260 characters, my
code fails.

I could split the full path and traverse through the
hierarchy, but it's ugly and possibly slower. I was hoping
to find out whether I can increase that maximum length.

Thanks,
Donald Xie
 
Back
Top