C# 文件操作函数 创建文件 判断存在
程序员文章站
2023-11-22 15:00:04
文件创建:
复制代码 代码如下:file.create(application.startuppath + "\\alarmset.txt");//创建该文件
sys...
文件创建:
复制代码 代码如下:
file.create(application.startuppath + "\\alarmset.txt");//创建该文件
system.io.path.getfilename(filepath) //返回带扩展名的文件名
system.io.path.getfilenamewithoutextension(filepath) //返回不带扩展名的文件名
system.io.path.getdirectoryname(filepath) //返回文件所在目录
system.io.path.getfilename(filepath) //返回带扩展名的文件名
system.io.path.getfilenamewithoutextension(filepath) //返回不带扩展名的文件名
system.io.path.getdirectoryname(filepath) //返回文件所在目录
文件存在:
复制代码 代码如下:
file.exists(application.startuppath + "\\alarmset.txt")
system.io.directoryinfo info = new system.io.directoryinfo(application.startuppath + "\\alarmset.txt");
messagebox.show(info.exists.tostring());
system.io.directoryinfo info = new system.io.directoryinfo(application.startuppath + "\\alarmset.txt");
messagebox.show(info.exists.tostring());
是不是很简单,但有时候我们可能对getfilenamewithoutextension或getdirectoryname这样的函数,感觉比较陌生,以前还总傻傻的自己写函数实现,原来就一行代码搞定啊~