This project is read-only.

FileInfo Constructor Glitch/Annoyance

Apr 7, 2010 at 7:30 PM

Hello... I've been playing with AlphaFS the last couple of days and I must say it looks really impressing... However, I bumped into a minor glitch/annoyance...

In my project I have this simple piece of code:

fsi = new FileInfo(path);

According to the FileInfo constructor documentation path may be either a relative or a fully qualified name...

However when I use a relative path (for example ../../SomeFile.cs) an exception is thrown from the constructor... If I translate to a full path (as shown below) the code works just fine...

fsi = new FileInfo(Path.GetFullPath(path));

Upon further investigating the constructor code it looks like the constructor checks if the supplied path is rooted (it is not) and then proceeds to check the validity of the path as a simple name (through a call to IsValidName). The check fails (due to the invalid character / being contained in the path) and an exception is thrown. That is, the constructor doesn't seem to account for this specific case of relative paths...

I don't know if this is per-design but it doesn't seem natural to me especially since:

  • the documentation suggests that relative paths are allowed
  • the framework already knows how to translate between relative and full paths (and therefore could transparently do so, in the constructor)
  • the Microsoft supplied System.IO.FileInfo class handles the above case seamlessly

I don't know if the call to IsValidName should be changed to IsValidPath and I 'm afraid it might break something else...

 

Thanks in advance!!

Apr 7, 2010 at 7:37 PM
did you try ..\..\..\SomeFile.cs ?


On 7 April 2010 11:30, RetroSonic <notifications@codeplex.com> wrote:
> From: RetroSonic
>
> Hello... I've been playing with AlphaFS the last couple of days and I must
> say it looks really impressing... However, I bumped into a minor
> glitch/annoyance...
>
> In my project I have this simple piece of code:
>
> fsi = new FileInfo(path);
>
> According to the FileInfo constructor documentation path may be either a
> relative or a fully qualified name...
>
> However when I use a relative path (for example ../../SomeFile.cs) an
> exception is thrown from the constructor... If I translate to a full path
> (as shown below) the code works just fine...
>
> fsi = new FileInfo(Path.GetFullPath(path));
>
> Upon further investigating the constructor code it looks like the
> constructor checks if the supplied path is rooted (it is not) and then
> proceeds to check the validity of the path as a simple name (through a call
> to IsValidName). The check fails (due to the invalid character / being
> contained in the path) and an exception is thrown. That is, the constructor
> doesn't seem to account for this specific case of relative paths...
>
> I don't know if this is per-design but it doesn't seem natural to me
> especially since:
>
> the documentation suggests that relative paths are allowed
> the framework already knows how to translate between relative and full paths
> (and therefore could transparently do so, in the constructor)
> the Microsoft supplied System.IO.FileInfo class handles the above case
> seamlessly
>
> I don't know if the call to IsValidName should be changed to IsValidPath and
> I 'm afraid it might break something else...
>
>
>
> Thanks in advance!!
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe or change your settings on codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at codeplex.com



--
Sincerely,
Alexander N.
Apr 7, 2010 at 9:22 PM
I've got a bug fix now, and will check it in shortly, So you should update to latest Development branch.
Apr 8, 2010 at 11:19 AM

Wow... That was fast!!!

Thanks...