當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


haskell renameFile用法及代碼示例

Haskell語言Directory模塊中函數renameFile的用法及代碼示例。

用法類型:

FilePath -> FilePath -> IO ()

renameFileold new將現有文件係統對象的名稱從old更改為new。如果新對象已經存在,則將其原子替換為舊對象。這兩個路徑都不能引用現有目錄。一致的實現不必在所有情況下都支持重命名文件(例如,在不同的物理設備之間重命名),但是必須記錄約束。

示例1:

源碼:

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)

輸出:
(True,False,True)
         

注:本文由純淨天空篩選整理自 haskell renameFile。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。