ZVON > References > Haskell reference
| Indexes | Syntax | Prelude | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | >> Directory << | System | Time | Locale | CPUTime | Random

Module: Directory
Function: renameFile
Type: FilePath -> FilePath -> IO ()
Description: renameFile old new changes the name of an existing file system object from old to new. If the new object already exists, it is atomically replaced by the old object. Neither path may refer to an existing directory. A conformant implementation need not support renaming files in all situations (for instance, renaming across different physical devices), but the constraints must be documented.
Related:

Example 1
Program source: 

import IO
import Directory

main = do hdl <- openFile "/tmp/foo.txt" WriteMode
	  hPutStr hdl "HELLO"
	  hClose hdl
	  a <- doesFileExist "/tmp/foo.txt"
	  renameFile "/tmp/foo.txt" "/tmp/bar.txt"
	  b <- doesFileExist "/tmp/foo.txt"
	  c <- doesFileExist "/tmp/bar.txt"
	  print (a,b,c)

Output: (True,False,True)