4 ms·
> What's the idiom for chdir'ing to a subdirectory such that you pop back out again when you're done This can be done with the "bracket" function, which works
by danidiaz 12y ago
> What's the idiom for chdir'ing to a subdirectory such that you pop back out again when you're done
This can be done with the "bracket" function, which works roughly like a context manager in Python:
import Control.Exception
import System.Directory
withDirectory :: FilePath -> IO a -> IO a
withDirectory path action = bracket (getCurrentDirectory <* setCurrentDirectory path)
setCurrentDirectory
(const action)