Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get file/folder properties #57

Closed
noughtmare opened this issue Jun 5, 2016 · 4 comments
Closed

Add ability to get file/folder properties #57

noughtmare opened this issue Jun 5, 2016 · 4 comments
Assignees
Labels
type: a-feature-request This is a request for a new feature.
Milestone

Comments

@noughtmare
Copy link

Is it possible to add a function like:

getProperties :: FilePath -> IO Properties

data Properties = Properties {
  name :: String
  type :: String
  size :: Integer
  etc...
}

Thank you!

@Rufflewind Rufflewind added the type: a-feature-request This is a request for a new feature. label Jun 6, 2016
@Rufflewind
Copy link
Member

  • name: Basename of the file?
  • type: What do you mean by type of a file? Mind giving some examples?
  • size: This is useful. I was not able to find another library that does this portably.
  • etc: Would you mind clarifying which properties you are interested in?

@noughtmare
Copy link
Author

Sorry, I was being way to vague and general.

For my current project I really only need a function that gets the mime type of a file (i.e. image/jpeg) and a function that checks if a filepath is a directory:

getMIMEType :: FilePath -> IO String
isDirectory :: FilePath -> IO Bool

@Rufflewind
Copy link
Member

Since MIME types are not stored as part of the files themselves, there is no accurate way to determine the MIME type without applying a tedious set of heuristic algorithms on the contents of the files. Unfortunately, this means it does not lie within the scope of directory. Consider using the magic library instead.

isDirectory might be a useful addition. Currently, there is doesDirectoryExist, which doesn't quite do the same thing but suffices for many albeit not all purposes.

@Rufflewind
Copy link
Member

Rufflewind commented Jun 13, 2016

So I went ahead and implemented the following:

  • getFileSize :: FilePath -> IO Integer
  • doesPathExist :: FilePath -> IO Bool

I was originally going to implement isDirectory, but I felt that adding doesPathExist is more useful, since it can be used to implement both isDirectory and isFile, while also avoiding naming conflicts with unix.

One could then implement isDirectory like this:

isDirectory :: FilePath -> IO Bool
isDirectory path = do
  exists <- doesPathExist path
  if exists
    then doesDirectoryExist path
    else ioError (mkIOError doesNotExistErrorType "isDirectory" Nothing (Just path))

@Rufflewind Rufflewind added this to the 1.2.7.0 milestone Jun 20, 2016
@Rufflewind Rufflewind self-assigned this Jun 20, 2016
Rufflewind added a commit to Rufflewind/directory that referenced this issue Jun 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: a-feature-request This is a request for a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants