Created
February 27, 2015 12:46
-
-
Save MiyamonY/f37bfca643a0eddafcf9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
import System.Directory | |
import System.IO | |
import Control.Exception | |
import qualified Data.ByteString.Lazy as B | |
main :: IO () | |
main = do | |
(fileName : fileName2: _) <- getArgs | |
copy fileName fileName2 | |
copy :: String -> String -> IO() | |
copy source dest = do | |
contents <- B.readFile source | |
bracketOnError | |
(openTempFile "." "temp") | |
(\ (tempName, tempHandle) -> do | |
hClose tempHandle | |
removeFile tempName) | |
(\ (tempName, tempHandle) -> do | |
B.hPutStr tempHandle contents | |
hClose tempHandle | |
renameFile tempName dest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment