
Hello, I'm implementing a command which manipulates files both on Unix/Mac and Windows. I was very surprised because there is not "getStatusChangeTime" function. So, I wrote it with CPP. http://github.com/kazu-yamamoto/Mew/blob/master/bin/hs/Stat.hs Another problem is that since '\\' is used as the file separator of Windows, I cannot use regular expression naturally for file path. In many programming languages, '/' is only file separator for programmers. And my friend, who is an expert of Windows API, says to me that Windows API allows '/' as a file separator. Why don't we use '/' on Windows, too? Are there any abstracted file library to solve these problems? Or should I start to write such a library? --Kazu

Excerpts from Kazu Yamamoto (山本和彦)'s message of Tue Apr 27 04:59:46 +0200 2010:
Hello,
I'm implementing a command which manipulates files both on Unix/Mac and Windows. I was very surprised because there is not "getStatusChangeTime" function. So, I wrote it with CPP.
http://github.com/kazu-yamamoto/Mew/blob/master/bin/hs/Stat.hs
Another problem is that since '\\' is used as the file separator of Windows, I cannot use regular expression naturally for file path. In
Clarify this, please. Used by who? The user may enter \\ which is valid on Windows. Both Cabal and filepath libraries do have functions operating on filepath strings. Eg filepath can split them. I agree that / is valid on Windows. So before working on user input you have to sanitize paths by replacing \\ by /
Are there any abstracted file library to solve these problems? Or should I start to write such a library?
Which functions should this library have? I'm pretty sure that filepath already has most functions you need. You may want to patch it so that it's using / on Windows when assembling paths form lists of directory names. Marc Weber

Hello,
Clarify this, please. Used by who?
It is by System.FilePath. Windows: combine "home" "bob" == "home\\bob"
Both Cabal and filepath libraries do have functions operating on filepath strings. Eg filepath can split them.
I'm want to use regular expressions for results of 'combine', for instance.
Are there any abstracted file library to solve these problems? Or should I start to write such a library?
Which functions should this library have?
isSymbolicLink, linkCounts, etc.
I'm pretty sure that filepath already has most functions you need.
Not really at least to me. --Kazu

Hi Kazu, I don't have a ghc Windows installation at the moment so I can't test. filepath has functions such as normalise and equalFilePath. Have a look at splitPath which is using pathSeparators which allows both \\ and / on Windows. filpath is using \\ to join pathes though. So appling normalise on filepath on Windowsn will result in having paths containing \\ only. This will still not help you writing your regex unless you replace / by \\ on Windows. It's easy to write [\\/] in regex to catch both. So maybe a normalisePosix function should be added which always returns / ? The fast way which would work for you only is making pathSeparator return "/" only. Then you're done but your code will not be portable.. Including a local copy of filepath for exactly this reason could be an option for you.
isSymbolicLink, linkCounts, etc.
Don't know about them.. Marc Weber
participants (2)
-
Kazu Yamamoto
-
Marc Weber