这个删除文件到回收站的代码有什么错误?请指教。

javaduke 2002-10-13 10:11:53
[StructLayout(LayoutKind.Sequential)]
private struct SHFILEOPSTRUCT
{
public System.IntPtr hWnd;
public System.Int32 wFunc;
[MarshalAs(UnmanagedType.LPStr)]
public System.String pFrom;
[MarshalAs(UnmanagedType.LPStr)]
public System.String pTo;
public System.Int32 fFlags;
public System.Int32 fAnyOperationsAborted;
public System.IntPtr hNameMappings;
[MarshalAs(UnmanagedType.LPStr)]
public System.String lpszProgressTitle;
}
public static int ShellDelete(string file){
SHFILEOPSTRUCT fstruct=new SHFILEOPSTRUCT();
fstruct.hWnd=IntPtr.Zero;
fstruct.wFunc=3;
fstruct.pFrom=file;
fstruct.pTo=null;
fstruct.fFlags=64;
//fstruct.fAnyOperationsAborted=false;
fstruct.hNameMappings=null;
//fstruct.lpszProgressTitle=null;
return SHFileOperation(ref fstruct);
}
用ShellDelete("G:\\1.bmp");总提示找不到文件或者磁盘。
why?
...全文
71 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
javaduke 2002-10-26
  • 打赏
  • 举报
回复
搞定了,FileName+"\0\0"即可。
yarshray 2002-10-25
  • 打赏
  • 举报
回复
System.IO.File.Delete(@"G:/1.bmp");
.net标准方法!
yarshray 2002-10-25
  • 打赏
  • 举报
回复
try:
ShellDelete(@"G:\1.bmp");
javaduke 2002-10-25
  • 打赏
  • 举报
回复
为什么有的文件可以删除,有的便不可以,同样的文件一会可以删除,一会不可删除。谁可给我一个好用的代码?
snewxf 2002-10-13
  • 打赏
  • 举报
回复
一般是你的1.bmp这个文件跟本不存在!
idiotzeng 2002-10-13
  • 打赏
  • 举报
回复
“总提示找不到文件或者磁盘”提示了一次,就再也没出现了,怪事
qiushuiwuhen 2002-10-13
  • 打赏
  • 举报
回复
我这正常,测试数据
ShellDelete(@"d:\a.gif");

是不是忘加了
[DllImport("shell32")]
static extern void SHFileOperation(ref SHFILEOPSTRUCT fstruct);
另外我去掉了ShellDelete 返回值
public static void ShellDelete(string file){
SHFILEOPSTRUCT fstruct=new SHFILEOPSTRUCT();
fstruct.hWnd=IntPtr.Zero;
fstruct.wFunc=3;
fstruct.pFrom=file;
fstruct.pTo=null;
fstruct.fFlags=64;
fstruct.hNameMappings=IntPtr.Zero;
SHFileOperation(ref fstruct);
}
javaduke 2002-10-13
  • 打赏
  • 举报
回复
还是不行,究竟错在那里,莫名其妙。

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧