Closed fayilt closed 4 years ago
I could work around it if fileSystem.Directory.Exists(path) would return false for files, but it returns true for any existing path.
I'll look into this this evening, Directory.Exists should only return true if it is actually a directory. In the mean time, you should be able to use File.GetAttributes
to determine if it is a file or directory.
Thanks @jordanlytle, doesn't look like you can use File.GetArrtibutes on a directory, I get STATUS_FILE_IS_A_DIRECTORY.
It calls FromFileName to get IFileInfo, and inside that we do this:
CreateOptions createOptions = CreateOptions.FILE_SYNCHRONOUS_IO_NONALERT | CreateOptions.FILE_NON_DIRECTORY_FILE;
status = fileStore.CreateFile(out handle, out FileStatus fileStatus, relativePath, accessMask, 0, shareAccess, disposition, createOptions, null);
Would it make sense to have GetFileSystemItemAttributes method on the FileSystem itself?
That wasn't the result I was expecting, but it does tell you that it is a directory. I'm going to start working on fixing Directory.Exists now and will hopefully have a fix out tonight.
It wouldn't really make sense to add anything to FileSytem that doesn't exist in the interface (which is from System.IO.Abstractions and we don't control) since it isn't intended to be accessed that way.
What's the best way to determine whether a path is a file or a folder? You seem to only be able to operate either with a file or a folder and you need to know in advance. There is no way to create a "file system item" and get its attributes.