1 /// <summary>
2 /// 移动文件
3 /// </summary>
4 /// <param name="oldPath">源文件路径</param>
5 /// <param name="newPath">目标文件路径</param>
6 /// <param name="fileName">文件名称</param>
7 public static void MoveFile(string oldPath, string newPath, string fileName)
8 {
9 if (!Directory.Exists(newPath))
10 {
11 //不存在则自动创建文件夹
12 Directory.CreateDirectory(newPath);
13 }
14 File.Move(oldPath + fileName, newPath + fileName);
15 }
16
17 /// <summary>
18 /// 批量移动文件
19 /// </summary>
20 /// <param name="oldPath">源文件路径</param>
21 /// <param name="newPath">目标文件路径</param>
22 /// <param name="fileNameList">文件名称</param>
23 public static void MoveFile(string oldPath, string newPath, ArrayList fileNameList)
24 {
25 if (!Directory.Exists(newPath))
26 {
27 //不存在则自动创建文件夹
28 Directory.CreateDirectory(newPath);
29 }
30 for (int i = 0; i < fileNameList.Count; i++)
31 {
32 File.Move(oldPath + fileNameList[i], newPath + fileNameList[i]);
33 }
34 }
35
36 /// <summary>
37 /// 删除文件
38 /// </summary>
39 /// <param name="path">文件路径</param>
40 /// <returns>删除结果,成功或失败</returns>
41 public static bool DeleteFile(string path)
42 {
43 try
44 {
45 File.Delete(path);
46 return true;
47 }
48 catch
49 {
50 return false;
51 }
52 }
53
54 /// <summary>
55 /// 删除文件夹
56 /// </summary>
57 /// <param name="path">文件夹路径</param>
58 /// <returns>删除结果,成功或失败</returns>
59 public static bool DeleteFolder(string path)
60 {
61 try
62 {
63 Directory.Delete(path);
64 return true;
65 }
66 catch
67 {
68 return false;
69 }
70 }
71
72 /// <summary>
73 /// 移动文件夹
74 /// </summary>
75 /// <param name="oldPath">源文件夹路径</param>
76 /// <param name="newPath">目标文件夹路径</param>
77 /// <returns>移动结果</returns>
78 public static bool MoveFolder(string oldPath, string newPath)
79 {
80 try
81 {
82 Directory.Move(oldPath, newPath);
83 return true;
84 }
85 catch
86 {
87 return false;
88 }
89 }