File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ module Path.IO
1414 ,removeTree
1515 ,removeTreeIfExists
1616 ,fileExists
17- ,dirExists )
17+ ,dirExists
18+ ,copyDirectoryRecursive )
1819 where
1920
2021import Control.Exception hiding (catch )
@@ -150,3 +151,24 @@ fileExists =
150151dirExists :: MonadIO m => Path b Dir -> m Bool
151152dirExists =
152153 liftIO . doesFileExist . toFilePath
154+
155+ -- | Copy a directory recursively. This just uses 'copyFile', so it is not smart about symbolic
156+ -- links or other special files.
157+ copyDirectoryRecursive :: (MonadIO m ,MonadThrow m )
158+ => Path Abs Dir -- ^ Source directory
159+ -> Path Abs Dir -- ^ Destination directory
160+ -> m ()
161+ copyDirectoryRecursive srcDir destDir =
162+ do liftIO (createDirectoryIfMissing False (toFilePath destDir))
163+ (srcSubDirs,srcFiles) <- listDirectory srcDir
164+ forM_ srcFiles
165+ (\ srcFile ->
166+ case stripDir srcDir srcFile of
167+ Nothing -> return ()
168+ Just relFile -> liftIO (copyFile (toFilePath srcFile)
169+ (toFilePath (destDir </> relFile))))
170+ forM_ srcSubDirs
171+ (\ srcSubDir ->
172+ case stripDir srcDir srcSubDir of
173+ Nothing -> return ()
174+ Just relSubDir -> copyDirectoryRecursive srcSubDir (destDir </> relSubDir))
You can’t perform that action at this time.
0 commit comments