If the directory you want to delete contains read-only files, they will not be deleted on Windows, but on Linux.
There is removePathForcibly, but it was introduced only recently .
, , . removeDirectoryRecursive.
import Control.Monad (forM_, when)
import System.FilePath ((</>))
import qualified System.Directory as FileSystem
-- Recursively makes all files and directories in a directory writable.
-- On Windows this is required to be able to recursively delete the directory.
makeWritableRecursive :: FilePath -> IO ()
makeWritableRecursive path = do
permissions <- FileSystem.getPermissions path
FileSystem.setPermissions path (FileSystem.setOwnerWritable True permissions)
isDirectory <- FileSystem.doesDirectoryExist path
when isDirectory $ do
contents <- FileSystem.listDirectory path
forM_ [path </> item | item <- contents] makeWritableRecursive