【发布时间】:2019-03-12 14:58:25
【问题描述】:
我正在尝试编写接收[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 也没有任何反应。
我在这里缺少什么?非常感谢!
【问题讨论】:
标签: functional-programming clean-language