제거 할 디렉토리에 읽기 전용 파일이 포함되어 있으면 제거하는 것이 Windows에서는 실패하지만 Linux에서는 실패합니다.
removePathForcibly
가 있지만, 소개 된 것은 very 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
당신이 비어 있지의 디렉토리를 제거 할 수 없습니다 ... –
@MarcB : 그것은 removeDirectoryRecursive'이 _recursive_ 왜'이다 : 그것은 재귀 적으로 디렉토리를 삭제하기 전에 모든 내용을 삭제합니다. 문제가 무엇인지 알았고 같은 문제가 발생할 수있는 다른 사람들을 돕기 위해 해결책을 여기에서 공유했습니다. [Q & A 스타일] (https://stackoverflow.com/help/self-answer) – Ruud