Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created June 10, 2015 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/1f5cd000f7b2ecb62dce to your computer and use it in GitHub Desktop.
Save shigemk2/1f5cd000f7b2ecb62dce to your computer and use it in GitHub Desktop.
-- ./bytestring bart.txt bort.txt
import System.Environment
import System.Directory
import System.IO
import Control.Exception
import qualified Data.ByteString.Lazy as B
main = do
(fileName1:fileName2:_) <- getArgs
copy fileName1 fileName2
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