What is the proper way to safely create a temporary directory in Haskell? System.IO offers ways to create temporary files, but I can’t find anything that does the same for directories, neither there nor in System.Directory, System.Posix.Directory, nor System.Posix.Temp. Is there a function I’m overlooking, or do I need to write one myself? (And if so, are there any dangers to avoid, like there are with creating temporary files?)
What is the proper way to safely create a temporary directory in Haskell? System.IO
Share
For working specifically with Unix systems, the Unixutils package contains such a function:
withTemporaryDirectory :: FilePath -> (FilePath -> IO a) -> IO a
If you need it to work on both Windows and Unix systems, you’ll want to use the temporary package instead. It has the same function with a slightly different type signature:
withTemporaryDirectory :: FilePath -> String -> (FilePath -> IO a) -> IO a