網站首頁 編程語言 正文
1.獲取文件的路徑和移動到文件夾信息
string fileName = "";
string sourceFile = @"F:\Test文件夾\CSV";
string bakFilePath = @"F:\Test文件夾\CSV\bak";
2.獲取文件夾下文件信息,并移動到Bak操作。
//匹配.csv的文件路徑地址集合
string[] FullfillfilesList = Directory.GetFiles(sourceFile, "*.csv", 0);
if (FullfillfilesList.Length > 0)
{
foreach (string Fullfillfiles in FullfillfilesList)
{
//每一個文件名稱
fileName = Fullfillfiles.Substring(Fullfillfiles.LastIndexOf('\\') + 1);
//移動到Bak文件夾
ExecutionResult res = MoveFileToBak(sourceFile + "/" + fileName, bakFilePath, fileName);
}
}
3.文件移動到Bak方法
public static ExecutionResult MoveFileToBak(string sourceFile, string bakFilePath, string bakFileName)
{
ExecutionResult result;
FileInfo tempFileInfo;
FileInfo tempBakFileInfo;
DirectoryInfo tempDirectoryInfo;
result = new ExecutionResult();
tempFileInfo = new FileInfo(sourceFile);
tempDirectoryInfo = new DirectoryInfo(bakFilePath);
tempBakFileInfo = new FileInfo(bakFilePath + "\\" + bakFileName);
try
{
if (!tempDirectoryInfo.Exists)
tempDirectoryInfo.Create();
if (tempBakFileInfo.Exists)
tempBakFileInfo.Delete();
//move file to bak
tempFileInfo.MoveTo(bakFilePath + "\\" + bakFileName);
result.Status = true;
result.Message = "Move File To Bak OK";
result.Anything = "SEND OK";
}
catch (Exception ex)
{
result.Status = false;
result.Anything = "SEND Fail";
result.Message = ex.Message;
}
return result;
}
原文鏈接:https://www.cnblogs.com/wml-it/p/12914868.html
相關推薦
- 2022-05-12 Python繪制計算機CPU占有率變化的折線圖_python
- 2023-12-06 Warn: Could not find @TableId
- 2022-07-24 搭建React?Native熱更新平臺的詳細過程_React
- 2022-06-28 ES6基礎語法之Map和Set對象_基礎知識
- 2022-09-16 c#解析jobject的數據結構_C#教程
- 2022-10-19 Pandas如何對Categorical類型字段數據統計實戰案例_python
- 2022-05-13 Django-Rest framwork框架 序列化與反序列化
- 2022-12-27 python中getopt()函數用法詳解_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支