建立兩個類用於完成檔案和資料夾的相關操作

2022-03-27 23:59:29 字數 3271 閱讀 9621

using system;

using system.collections.generic;

using system.text;

using system.io;

namespace filediropreate

else

}///

/// gets the name of the file.包括檔案的副檔名

///

/// 檔案的全路徑

///

public string getfilename(string filefullpath)

else

}///

/// gets the name of the file.

///

/// 檔案的全路徑

/// 是否包含檔案的副檔名

///

public string getfilename(string filefullpath, bool includeextension)

else

}else

}///

/// gets the file extension.

///

/// the file full path.

///

public string getfileextension(string filefullpath)

else

}///

/// opens the file.

///

/// the file full path.

///

public bool openfile(string filefullpath)

else

}///

/// gets the size of the file.

///

/// the file full path.

///

public string getfilesize(string filefullpath)

else if (fl > 1024 * 1024)

else

}else

}///

/// files to stream byte.

///

/// the file full path.

///

public byte filetostreambyte(string filefullpath)

else

}///

/// bytes the stream to file.

///

/// the create file full path.

/// the stream byte.

///

public bool bytestreamtofile(string createfilefullpath, byte streambyte)

filestream fs;

fs = file.create(createfilefullpath);

fs.write(streambyte, 0, streambyte.length);

fs.close();

return true;

}catch

}///

/// 序列化xml檔案

///

/// the file full path.

///

public bool serializexmlfile(string filefullpath)

catch

///

/// 反序列化xml檔案

///

/// the file full path.

///

public bool deserializexmlfile(string filefullpath)

catch}}

public class diroperate

///

/// 建立資料夾

///

/// the dir full path.

/// the dir operate option.

///

public bool createdir(string dirfullpath, operateoption diroperateoption)

else if (diroperateoption == operateoption.existdelete)

return true;

}catch

}///

/// 刪除資料夾

///

/// 全稱路徑.

///

public bool deletedir(string dirfullpath)

else

}///

/// 得到目錄內的檔名,僅在當前指定的目錄下

///

/// 指定的目錄名

///

public string getdirfiles(string dirfullpath)

return filelist;

}///

/// 得到目錄內的檔名,

///

/// t指定的目錄名

/// the so.

///

public string getdirfiles(string dirfullpath, searchoption so)

return filelist;

}///

///  得到目錄內的檔名,

///

/// the dir full path.

/// the search pattern.

///

public string getdirfiles(string dirfullpath, string searchpattern)

return filelist;

}///

///  得到目錄內的檔名,

///

/// the dir full path.

/// the search pattern.

/// the so.

///

public string getdirfiles(string dirfullpath, string searchpattern, searchoption so)

return filelist;}}

}

Python操做檔案和資料夾,完成檔案移動 複製

檔案 資料夾的移動 複製 刪除 重新命名 匯入shutil模組和os模組 import shutil,os 複製單個檔案 shutil.copy c a 1.txt c b 複製並重命名新檔案 shutil.copy c a 2.txt c b 121.txt 複製整個目錄 備份 shutil.co...

Linux建立 刪除 檔案和資料夾

linux建立 刪除 檔案和資料夾 1 建立檔案 touch 檔名 例項如下 touch paras.txt 在當前目錄下建立檔案paras.txt touch a b c paras.txt 在已存在目錄下 a b c 下建立檔案paras.txt 2 建立資料夾 mkdir option dir...

Android建立資料夾和檔案

1 電子證據存放基本路徑 2private static string basepath 3 電子證據存放根路徑 4private static string evidencepath 5 基本存放路徑 6private static string imagebasepath 1 2 1 判斷sd卡...