C# 文件流操作 之 删除、复制、转移多个文件
?????? /// <summary>
??????? /// 刪除文件夾下面所有圖片
??????? /// </summary>
??????? /// <param name="oldpngPath">待刪除文件路徑</param>
??????? /// <param name="newpngPath">刪除到的新目錄</param>
??????? /// <param name="geshi">操作文件的格式 例如:*.png、*.xml</param>
??????? public void deleteAll(string delpath, string geshi)
??????? {
??????????? string[] files = Directory.GetFiles(delpath, geshi);
??????????? foreach (string file in files)
??????????? {
??????????????? File.Delete(file);
??????????? }
??????? }
?
??????? /// <summary>
??????? /// 復制文件夾下面所有圖片
??????? /// </summary>
??????? /// <param name="oldpngPath">待復制文件路徑</param>
??????? /// <param name="newpngPath">復制到的新目錄</param>
??????? /// <param name="geshi">操作文件的格式 例如:*.png、*.xml</param>
??????? public void copyALl(string oldpngPath, string newpngPath, string geshi)
??????? {
??????????? string[] files = Directory.GetFiles(oldpngPath, geshi);
??????????? foreach (string file in files)
??????????? {
??????????????? string otherFile = Path.Combine(oldpngPath, Path.GetFileName(file));
??????????????? File.Copy(file, newpngPath + "\\" + Path.GetFileName(file));
??????????? }
??????? }
?
?????? /// <summary>
??????? /// 移動文件夾下的所有文件
??????? /// </summary>
??????? /// <param name="olderpath">待移動的文件目錄</param>
??????? /// <param name="topath">新目錄</param>
??????? public void moveAll(string olderpath, string topath)
??????? {
??????????? string[] files = Directory.GetFiles(delpath, geshi);
??????????? foreach (string file in files)
??????????? {
??????????????? File.Move(file, topath); //移動文件
??????????? }
??????? }
轉載于:https://blog.51cto.com/fengbo1983/500161
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的C# 文件流操作 之 删除、复制、转移多个文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 胃胀气消化不良怎么办有什么办法(胃胀气消
- 下一篇: 你会在C#的类库中添加web servi