C# 文件操作函數(shù) 創(chuàng)建文件 判斷存在
更新時(shí)間:2016年05月25日 11:04:41 作者:秦風(fēng)
本文列舉了C#中文件操作中常用的函數(shù),創(chuàng)建文件和判斷文件存不存在的基本使用,簡(jiǎn)單實(shí)用,希望能幫到大家。
文件創(chuàng)建:
復(fù)制代碼 代碼如下:
File.Create(Application.StartupPath + "\\AlarmSet.txt");//創(chuàng)建該文件
System.IO.Path.GetFileName(filePath) //返回帶擴(kuò)展名的文件名
System.IO.Path.GetFileNameWithoutExtension(filePath) //返回不帶擴(kuò)展名的文件名
System.IO.Path.GetDirectoryName(filePath) //返回文件所在目錄
System.IO.Path.GetFileName(filePath) //返回帶擴(kuò)展名的文件名
System.IO.Path.GetFileNameWithoutExtension(filePath) //返回不帶擴(kuò)展名的文件名
System.IO.Path.GetDirectoryName(filePath) //返回文件所在目錄
文件存在:
復(fù)制代碼 代碼如下:
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());
是不是很簡(jiǎn)單,但有時(shí)候我們可能對(duì)GetFileNameWithoutExtension或GetDirectoryName這樣的函數(shù),感覺比較陌生,以前還總傻傻的自己寫函數(shù)實(shí)現(xiàn),原來就一行代碼搞定啊~
相關(guān)文章
C# WinForm程序設(shè)計(jì)簡(jiǎn)單計(jì)算器
這篇文章主要為大家詳細(xì)介紹了C# WinForm程序設(shè)計(jì)簡(jiǎn)單計(jì)算器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02
C# TabControl控件中TabPage選項(xiàng)卡切換時(shí)的觸發(fā)事件問題
這篇文章主要介紹了C# TabControl控件中TabPage選項(xiàng)卡切換時(shí)的觸發(fā)事件問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
C#實(shí)現(xiàn)從windows剪貼板獲取內(nèi)容的方法
這篇文章主要介紹了C#實(shí)現(xiàn)從windows剪貼板獲取內(nèi)容的方法,涉及C#操作剪貼板的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-05-05

