C# 文件操作函数 创建文件 判断存在


文件创建:

\\AlarmSet.txt");//创建该文件
System.IO.Path.GetFileName(filePath)       //返回带扩展名的文件名
System.IO.Path.GetFileNameWithoutExtension(filePath)     //返回不带扩展名的文件名
System.IO.Path.GetDirectoryName(filePath)     //返回文件所在目录

文件存在:

\\AlarmSet.txt") 
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(Application.StartupPath + "\\AlarmSet.txt"); 
MessageBox.Show(info.Exists.ToString());

是不是很简单,但有时候我们可能对GetFileNameWithoutExtension或GetDirectoryName这样的函数,感觉比较陌生,以前还总傻傻的自己写函数实现,原来就一行代码搞定啊~


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3