C Sharp(C#)中如何删除文件(文件夹)
C Sharp(C#)中如何删除文件(文件夹)
直接删除:
using System.IO;
...
string filePath = @"D:\...\xxx.xxx";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
else
{
Console.WriteLine("file not exist.");
Console.ReadLine();
}
删除到回收站:
using System.Runtime.InteropServices;
namespace CSharp
{
class Program
{
private const int FO_DELETE = 3;
private const int FOF_ALLOWUNDO = 0x40;
private const int FOF_NOCONFIRMATION = 0x0010;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
public struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
[MarshalAs(UnmanagedType.U4)]
public int wFunc;
public string pfrom;
public string pTo;
public short fFlags;
[MarshalAs(UnmanagedType.Bool)]
public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
public string lpszProgressTitle;
}
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
static void Main(string[] args)
{
string filePath = @"D:\...\xxx.xxx";
if (File.Exists(filePath))
{
SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
fileop.wFunc = FO_DELETE;
fileop.pfrom = filePath + '\0' + '\0';
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
SHFileOperation(ref fileop);
Console.WriteLine("delete ok");
Console.ReadLine();
}
else
{
Console.WriteLine("file not exist.");
Console.ReadLine();
}
}
}
}
相关文档:
源码:
# include <stdio.h>
int main()
{
/* 定义字符型变量,并给它们付初值 */
char c1, c2, c3, c4, c5, c6, c7;
c1 = 'C';
c2 = 'h';
c3 = 'i';
c4 = 'n';
& ......
源码:
# include <stdio.h>
int main( )
{
int radius;
double area;
for(radius = 1; radius <= 10 ; radius++)
{
area = 3.1416 * radius * radius;
......
源码:
# include <stdio.h>
int main()
{
/* 有尺寸 */
/* 一维整形数组初始化 */
int array1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
/* 一维字符型数组初始化,最后一个元素自动添加为‘/0 ......
源码:
# include <stdio.h>
void swap(int *x, int *y);
int main()
{
int i, j;
i = 12;
j = 36;
printf("i and j before swapping: %d %d\n", i, j);
&nbs ......
java 与 c# 3des 加解密
主要差异如下:
1、 对于待加密解密的数据,各自的填充模式不一样
C#的模式有:ANSIX923、ISO10126、None、PKCS7、Zero,而Java有:NoPadding、PKCS5Padding、SSL3Padding
2、 各自默认的3DES实现,模式和填充方式不一样
C#的默认模式为CBC,默认填充方式为PKCS7; java的默认模式 ......