ispiro
ispiro

Reputation: 27713

How to check for paths that are too long?

I want to check for paths that are too long once for a whole list and only then copy/create them...

So I thought this would be good:

try
{
    FileInfo file = new FileInfo(path);
    string temp = file.FullName;
}
catch { }

however, no exception is thrown then.

I rather not hardcode the limits because they might change, and I might be missing a limit...

So how can I check for long paths?

Upvotes: 3

Views: 4359

Answers (2)

ispiro
ispiro

Reputation: 27713

It seems that the answer is given by Tim Schmelter here : In ILSpy it seems that GetFullPath uses MaxDirectoryLength(255) whereas CreateDirectory uses 248.

EDIT: It was made into an answer.

Upvotes: 4

SLaks
SLaks

Reputation: 888107

The Path.GetFullPath() method will throw a PathTooLongException.

Upvotes: 10

Related Questions