2010/01/03

"doesdirectoryexist" socket

ディレクトリかどうか知りたいときってあります
$ ghci
Prelude> import System.Directory
Prelude System.Directory> doesDirectoryExist "/tmp/scim-panel-socket:0-foo"
True
Prelude System.Directory> getDirectoryContents "/tmp/scim-panel-socket:0-foo"
*** Exception: /tmp/scim-panel-socket:0-foo: getDirectoryContents: inappropriate type (Not a directory)
どないやねん

System.Directory を見てみると
s_isdir で判断してるらしいんだけどなぁ、よく分かんないなぁ
doesFileExist は doesDirectoryExist に not 取ってるみたいな感じ

でー、ググった、けど良く分からんかったけど Posix 思いだした
System.Posix.Files ってあった
Prelude> import System.Posix.Files
Prelude System.Posix.Files> status <- getFileStatus "/tmp/scim-panel-socket:0-foo"
Prelude System.Posix.Files> isDirectory status
False
Prelude System.Posix.Files> isNamedPipe status
False
Prelude System.Posix.Files> isSocket status
True
これかー

Windows とか良く知らないし
更に Posix な世界から出たことがあまり無い気がしてるんですが
あ、Windows のこととりあえず無視しておけばいいのか!!
や、System.Win32 ってのがあるのか...

0 件のコメント:

コメントを投稿