日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#对于文件操作

發布時間:2024/4/14 C# 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#对于文件操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
StreamWriter sw = File.AppendText(Server.MapPath(".")+"""myText.txt");
sw.WriteLine(
"追逐理想");
sw.WriteLine(
"kzlll");
sw.WriteLine(
".NET筆記");
sw.Flush();
sw.Close();

//C#拷貝文件
string OrignFile,NewFile;
OrignFile
= Server.MapPath(".")+"""myText.txt";
NewFile
= Server.MapPath(".")+"""myTextCopy.txt";
File.Copy(OrignFile,NewFile,
true);

//C#刪除文件
string delFile = Server.MapPath(".")+"""myTextCopy.txt";
File.Delete(delFile);

//C#移動文件
string OrignFile,NewFile;
OrignFile
= Server.MapPath(".")+"""myText.txt";
NewFile
= Server.MapPath(".")+"""myTextCopy.txt";
File.Move(OrignFile,NewFile);

//C#創建目錄
// 創建目錄c:"sixAge
DirectoryInfo d=Directory.CreateDirectory("c:""sixAge");
// d1指向c:"sixAge"sixAge1
DirectoryInfo d1=d.CreateSubdirectory("sixAge1");
// d2指向c:"sixAge"sixAge1"sixAge1_1
DirectoryInfo d2=d1.CreateSubdirectory("sixAge1_1");
// 將當前目錄設為c:"sixAge
Directory.SetCurrentDirectory("c:""sixAge");
// 創建目錄c:"sixAge"sixAge2
Directory.CreateDirectory("sixAge2");
// 創建目錄c:"sixAge"sixAge2"sixAge2_1
Directory.CreateDirectory("sixAge2""sixAge2_1");

//遞歸刪除文件夾及文件
<%@ Page Language=C#%>
<%@ Import namespace="System.IO"%>
<Script runat=server>
public void DeleteFolder(string dir)
{
if (Directory.Exists(dir)) //如果存在這個文件夾刪除之
{
foreach(string d in Directory.GetFileSystemEntries(dir))
{
if(File.Exists(d))
File.Delete(d);
//直接刪除其中的文件
else
DeleteFolder(d);
//遞歸刪除子文件夾
}
Directory.Delete(dir);
//刪除已空文件夾
Response.Write(dir+" 文件夾刪除成功");
}
else
Response.Write(dir
+" 該文件夾不存在"); //如果文件夾不存在則提示
}

protected void Page_Load (Object sender ,EventArgs e)
{
string Dir="D:""gbook""11";
DeleteFolder(Dir);
//調用函數刪除文件夾
}

轉載于:https://www.cnblogs.com/alexusli/archive/2008/12/12/1353990.html

總結

以上是生活随笔為你收集整理的C#对于文件操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。