timothyhobbs | 7 Nov 20:16 2012
Picon

Cross platform method for getting the /actual/ contents of a directory

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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Brandon Allbery | 7 Nov 20:52 2012
Picon

Re: Cross platform method for getting the /actual/ contents of a directory

On Wed, Nov 7, 2012 at 2:16 PM, <timothyhobbs <at> seznam.cz> wrote:
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?

Windows treats dots in filenames specially as well, although differently specially.  I am not sure about . but .. certainly works on Windows if you're not in the drive's root.  There are some other situations where dots in names are rejected (two or more in a row, other than .. itself, IIRC?) because of backward compatibility. 

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b <at> gmail.com                                  ballbery <at> sinenomine.net
unix/linux, openafs, kerberos, infrastructure          http://sinenomine.net

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane