ref: VisualBasic.FileIO
This commit is contained in:
1 parent
c2083b517c
commit
bc8828e29c
3 files changed
+27
-2
No files matched your search
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System.ServiceModel" />
|
<Reference Include="System.ServiceModel" />
|
||||||
|
<Reference Include="Microsoft.VisualBasic" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -55,4 +55,19 @@ public static class DirectoryUtils {
|
|||||||
Create(destDirName);
|
Create(destDirName);
|
||||||
Directory.Move(PathUtils.ToLongPath(sourceDirName), PathUtils.ToLongPath(destDirName));
|
Directory.Move(PathUtils.ToLongPath(sourceDirName), PathUtils.ToLongPath(destDirName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除文件夹。
|
||||||
|
/// </summary>
|
||||||
|
public static void Delete(string dirPath, bool toRecycleBin = false) {
|
||||||
|
dirPath = PathUtils.ToLongPath(dirPath);
|
||||||
|
if (toRecycleBin) {
|
||||||
|
Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(dirPath,
|
||||||
|
Microsoft.VisualBasic.FileIO.UIOption.AllDialogs,
|
||||||
|
Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin,
|
||||||
|
Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException);
|
||||||
|
} else {
|
||||||
|
Directory.Delete(dirPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -65,8 +65,17 @@ public static class FileUtils {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除文件。
|
/// 删除文件。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Delete(string filePath) =>
|
public static void Delete(string filePath, bool toRecycleBin = false) {
|
||||||
File.Delete(PathUtils.ToLongPath(filePath));
|
filePath = PathUtils.ToLongPath(filePath);
|
||||||
|
if (toRecycleBin) {
|
||||||
|
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filePath,
|
||||||
|
Microsoft.VisualBasic.FileIO.UIOption.AllDialogs,
|
||||||
|
Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin,
|
||||||
|
Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException);
|
||||||
|
} else {
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 确定指定的文件是否存在。
|
/// 确定指定的文件是否存在。
|
||||||
|
|||||||
Reference in new issue
Block a user