创建多个文本文件
在应用程序上创建多个 *.txt 文件的巧妙方法是什么 启动即检查它们是否存在,如果不创建它们。 我需要创建大约 10 个文本文件。 我是否必须对每个文件都这样做:
var
MyFile: textfile;
ApplicationPath: string;
begin
ApplicationPath := ExtractFileDir(Application.ExeName);
if not FileExists(ApplicationPath + '\a1.txt') then
begin
AssignFile(MyFile, (ApplicationPath + '\a1.txt'));
Rewrite(MyFile);
Close(MyFile);
end
else
Abort;
end;
what would be a neat way to create multiple *.txt files on application
startup i.e check if they exist if not create them.
I need to create about 10 text files.
Will I have to do like this for every single file:
var
MyFile: textfile;
ApplicationPath: string;
begin
ApplicationPath := ExtractFileDir(Application.ExeName);
if not FileExists(ApplicationPath + '\a1.txt') then
begin
AssignFile(MyFile, (ApplicationPath + '\a1.txt'));
Rewrite(MyFile);
Close(MyFile);
end
else
Abort;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只想使用随后编号的文件名创建空文件(或重写现有文件),您可以尝试类似的操作。以下示例使用 CreateFile API功能。但请注意,有几件事可能会禁止您尝试创建文件!
如果您想在所有情况下创建(覆盖)它们,请使用 CREATE_ALWAYS 处置标志
或者如果您只想在文件不存在时创建它们,请使用 CREATE_NEW 处置标志
If you only want to create the empty files (or rewrite the existing) with subsequently numbered file names, you might try something like this. The following examples use the CreateFile API function. But pay attention that several things may forbid your file creation attempts!
If you want to create (overwrite) them in all circumstances, use CREATE_ALWAYS disposition flag
Or if you want to create the files only if they doesn't exist, use the CREATE_NEW disposition flag
也许是这样的:
Something like this, perhaps: