D语言新手问题 D语言文件操作

· Created · Last modified by Brian replied at · 1273 times read

这么多方便的方法……不错,写小工具方便的很。

需要使用D语言的std.file包

//写文件

std.file.write("abc.txt", "1 2\n4 1\n5 100");

//读文本

auto str = std.file.readText("abc.txt");

//删除文件

std.file.remove("abc.txt");

//取大小

auto size = std.file.getSize("abc.txt");

//复制文件

std.file.copy("abc.txt","abc1.txt");

//重命名

std.file.rename("abc.txt","abc1.txt");

//取当前目录

auto path = std.file.getcwd();

//文件是否存在

auto exist = std.file.exists("abc.txt");

//删除目录

std.file.rmdir("c://abc/");

//修改当前目录

std.file.chdir("c://test/");

//新建目录

std.file.mkdir("c://test/");

//取临时目录

auto dir = std.file.tempDir();

Login to reply