7 Nov 2012 20:16
Cross platform method for getting the /actual/ contents of a directory
<timothyhobbs <at> seznam.cz>
2012-11-07 19:16:39 GMT
2012-11-07 19:16:39 GMT
Hello,
I'm writing a function to find out if a given directory is empty. I came up with the obvious:
do{
contents <- getDirectoryContents "/home/timothy/works/current/anonGraph/empty/" ;
let
realContents
=
filter
(\file ->
case file of
"." -> False ;
".." -> False ;
_ -> True)
contents
in
return $
case realContents of
[] -> True ;
_ -> False}
And this works fine on linux, but I wonder. On other systems, is "." and ".." allowed as file names? Couldn't a windows user actually end up with a file name named "." and this method would fail?
Thank you
Timothy
I'm writing a function to find out if a given directory is empty. I came up with the obvious:
do{
contents <- getDirectoryContents "/home/timothy/works/current/anonGraph/empty/" ;
let
realContents
=
filter
(\file ->
case file of
"." -> False ;
".." -> False ;
_ -> True)
contents
in
return $
case realContents of
[] -> True ;
_ -> False}
And this works fine on linux, but I wonder. On other systems, is "." and ".." allowed as file names? Couldn't a windows user actually end up with a file name named "." and this method would fail?
Thank you
Timothy
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RSS Feed