如何将文件删除至回收站中

Hover 2000-02-15 05:54:00
我在写一工具软件中遇到的这个问题,请尽快回复
...全文
238 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
netmare 2000-02-15
  • 打赏
  • 举报
回复
见鬼!我写的明明是c语言中的'或'(就是一个竖线),怎么变成'and'了???!!!!
netmare 2000-02-15
  • 打赏
  • 举报
回复
再贴一次
#include <shellapi.h>
...
SHFILEOPSTRUCT s;
s.hwnd=NULL;
s.wFunc=FO_DELETE;
s.pFrom="e:\\t.txt";
s.fFlags=FOF_ALLOWUNDO and FOF_NOCONFIRMATION ;
SHFileOperation(&s);
...
其中的FOF_ALLOWUNDO表示放到回收站中,FOF_NOCONFIRMATION表示是否提示,如不加此项,会提问是否放到回收站中。

为什么' and '会变成了'and'?!
netmare 2000-02-15
  • 打赏
  • 举报
回复
#include <shellapi.h>
...
SHFILEOPSTRUCT s;
s.hwnd=NULL;
s.wFunc=FO_DELETE;
s.pFrom="e:\\t.txt";
s.fFlags=FOF_ALLOWUNDO and FOF_NOCONFIRMATION ;
SHFileOperation(&s);
...
其中的FOF_ALLOWUNDO表示放到回收站中,FOF_NOCONFIRMATION表示是否提示,如不加此项,会提问是否放到回收站中。
jiangtao 2000-02-15
  • 打赏
  • 举报
回复
the key is Win32 API: SHFileOperation

How can I delete a file to the Recycle Bin?

From: "Ed Lagerburg" <lagerbrg@euronet.nl>


program del;

uses
ShellApi;

//function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer; stdcall;

Var T:TSHFileOpStruct;
P:String;
begin
P:='C:\Windows\System\EL_CONTROL.CPL';
With T do
Begin
Wnd:=0;
wFunc:=FO_DELETE;
pFrom:=Pchar(P);
fFlags:=FOF_ALLOWUNDO
End;
SHFileOperation(T);
End.


From: bstowers@pobox.com (Brad Stowers)

There are some other quirks you should be aware of, too:

Give the complete file path for every file specified. Do not rely on the current directory, even if you change
to it right before the call. The SHFileOperation API is not "smart" enough to use the current directory if
one is not given for undo information. So, even if you give the FOF_ALLOWUNDO flag, it will not move
deleted files to the recycle bin because it doesn't know what path they came from, and thus couldn't
restore them to their original location from the recycle bin. It will simply delete the file from the current
directory.

MS has a documentation correction about the pFrom member. It says that for multiple files, each filename
is seperated by a NULL (#0) character, and the whole thing is terminated by double NULLs. You need
the double NULL whether or not you are passing multiple filenames. Sometimes it will work correctly
without them, but often not. That's because sometimes you get lucky and the memory following the end of
your string has a NULL there.

An example of how to do this would be:

var
FileList: string;
FOS: TShFileOpStruct;
begin
FileList := 'c:\delete.me'#0'c:\windows\temp.$$$'#0#0;
{ if you were using filenames in string variables: }
FileList := Filename1 + #0 + Filename2 + #0#0;

FOS.pFrom := PChar(FileList);

// blah blah blah
end;

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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