TruePath icon indicating copy to clipboard operation
TruePath copied to clipboard

Check if a file or directory

Open ForNeVeR opened this issue 1 year ago • 3 comments
trafficstars

There should be a method to check if a path represents an existing file or a directory.

Perhaps something like this?

struct LocalPath
{
  // …
  // null -> not exists
  public FileEntryKind? ReadKind() { … }
}

enum FileEntryKind
{
  File,
  Directory,
  // others: Junction, Symlink?
}

ForNeVeR avatar Apr 21 '24 20:04 ForNeVeR

I'd like to discuss a few things:

  1. Maybe we should introduce an additional type FileEntryKind.Unknown instead of nullable FileEntryKind for the ReadKind method? In my opinion, this will make the client code more obvious.

  2. Should TruePath understand that a particular file or directory is a Junction or SymLink? It seems to me that a library for path processing should not do file processing

y0ung3r avatar Apr 29 '24 11:04 y0ung3r

Maybe we should introduce an additional type FileEntryKind.Unknown instead of nullable FileEntryKind for the ReadKind method? In my opinion, this will make the client code more obvious.

Nullable FileEntryKind should signify the absence of a file. We may add Unknown for, well, unknown files. Not for the same cases when there is no file at all.

We may add FileEntryKind.Absent instead, to address the part of your message on null, but I have to say I like null more for that particular purpose. I am open for discussion, though. My motivation is that "no entry" shouldn't be a kind of a file entry. There is no entry, and thus its kind cannot be defined.

Should TruePath understand that a particular file or directory is a Junction or SymLink? It seems to me that a library for path processing should not do file processing

I believe it should. While you are correct that this somewhat blurs the limits of what TruePath does as a library, kind of a file entry often affects the semantics of file system traversal. So, I would prefer TruePath to be able to distinguish special file entry types such as junctions and symlinks, and expose this knowledge through the API.

File system traversal is something that's in TruePath is in charge of.

Besides, other path management libraries (e.g. java.nio.Path) also expose this knowledge somewhat.

ForNeVeR avatar Apr 29 '24 15:04 ForNeVeR

Linking a comment with some proposed behavioral aspects from a related PR: https://github.com/ForNeVeR/TruePath/pull/50#discussion_r1586835863

ForNeVeR avatar May 03 '24 22:05 ForNeVeR