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()
{
/* 定义一个整数类型的变量,用来存放后面算式的值 */
int logic;
int a = 1;
int b = 2;
int c = 3;
&n ......
源码:
# include <stdio.h>
int main()
{
int i, j, k;
int m, n, p;
i = 8;
j = 10;
k = 12;
/* 自增在操作数之前 */
  ......
源码:
# include <math.h>
# include <stdio.h> /* 数学函数库 */
int main()
{
/* 用s表示多项式的值,用t表示每一项的值 */
double s, t, x; // 此处用双精度声明变量
int n;
printf ......
一:C# 连接SQL数据库
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Server=myServerAddress;Database=myDataBase;User ID=myUse ......
用 Java 解密 C# 加密的数据(DES)
[原文地址:http://yidinghe.cnblogs.com/articles/449212.html]
今天碰上一件令我头大的事情。我们的系统要和一个外部系统进行通讯,传输方式是采用 DES 算法对消息进行加密,再用 BASE64 编码。不过对方系统是用 C# 写的。平台不一样,于是我和对面的老兄先测试一下加密解密。 ......