
Bryan O'Sullivan wrote:
Hi, Neil -
I'm writing some filesystem traversal code using filepath at the moment, and I am a bit disappointed to find it more error-prone and cumbersome than I had hoped.
The root of my problem is that splitFileName leaves a trailing path separator on the end of the first element of the tuple it returns:
splitFileName "foo/bar" ==> ("foo/", "bar")
If I'm recursing up a file hierarchy towards the root directory (a common thing to do), this trailing path separator is a pain. Either I forget that it's there and infinitely loop in the same directory over and over again, due to this behaviour:
splitFileName "foo/" ==> ("foo/", "")
FWIW I think you're right here. But I thought I'd mention the following trick I cooked up recently. It meant that I didn't run into the above problem, and might be relevant for what you're doing: pathParents = scanl1 (>) . splitDirectories -- > scanl1 (>) (splitDirectories "/a/b/c") -- ["/","/a","/a/b","/a/b/c"] Cheers, Simon