我正在尝试编写接收[String]
文件名的函数,String
即文件目录的名称和*f
. 该函数将在每个文件最后附加一个整数。
这是我到目前为止得到的:
import StdEnv
import StdFile
import FileManipulation
appendNumInEndOfVmFiles :: [String] String *f -> String
appendNumInEndOfVmFiles [] dirname w = "finished"
appendNumInEndOfVmFiles [x:xs] dirname w
# path = dirname +++ "\\\\" +++ x
# (ok,file,files) = fopen path FAppendText w
# file = fwritei 12 file
# (ok2,_) = fclose file w
= appendNumInEndOfVmFiles xs dirname w
Start w
// 1. Receive name of directory from the user.
# (io,w) = stdio w // open stdio
# io = fwrites "Enter name of directory:\n" io // ask for name
# (name,io) = freadline io // read in name
# name = name % (0, size name - 2) // remove \n from name
# (ok,w) = fclose io w // close stdio
| not ok = abort "Couldn't close stdio" // abort in case of failure
// 2. Get a list of all file names in that directory.
# (dir,w) = getDirectoryContents (RelativePath [PathDown name]) w
# fileList = getNamesOfFilesInDirectory (getEntriesList dir)
= appendNumInEndOfVmFiles (getVmFiles fileList) name w
假设getVmFiles
在我的FileManipulation.dcl
文件中定义并且在这个问题的上下文中name
是"myDir"
并且文件列表是["hello.vm","Wiki.vm"]
出于某种原因,即使我在屏幕上收到“完成”消息,文件也没有被修改。无论我给什么类型的整数fopen
,即使它FWriteText
或FWriteData
它仍然什么都不做......即使我正在使用fwritec
或fwrites
使用字符也没有发生任何事情。
我在这里缺少什么?非常感谢!