怎样实现在win2000下删除一个有文件的目录,急!急!急!急!(100分)

  • 主题发起人 主题发起人 sakura12
  • 开始时间 开始时间
S

sakura12

Unregistered / Unconfirmed
GUEST, unregistred user!
[red][/red][:(]怎样实现在win2000下删除一个有文件的目录,且无需按确定键,
如果是扔到回收站,怎样继续清空回收站?急!急!!急!!!!
 
最简单的方法,生成一个批处理文件:
delete/y 目录名
调用它,并删除该批处理文件就行了。
 
用SHFileOperation就可以!
在你的单元中use shellapi单元
具体使用方法看下面的定义就知道了.声明在ShellApi单元中已经直接定义,你可以直接
拿来用!
WINSHELLAPI int WINAPI SHFileOperation(
; ; LPSHFILEOPSTRUCT lpFileOp
);


typedef struct _SHFILEOPSTRUCT{
; ; HWND ; ; ; ; hwnd;
; ; UINT ; ; ; ; wFunc;
; ; LPCSTR ; ; ; pFrom;
; ; LPCSTR ; ; ; pTo;
; ; FILEOP_FLAGS fFlags;
; ; BOOL ; ; ; ; fAnyOperationsAborted;
; ; LPVOID ; ; ; hNameMappings;
; ; LPCSTR ; ; ; lpszProgressTitle;
} SHFILEOPSTRUCT, FAR *LPSHFILEOPSTRUCT;
;
Contains information that the SHFileOperation function uses to perform file operations.

hwnd
Window handle to the dialog box to display information about the status of the file operation.
wFunc
Operation to perform. This member can be one of the following values: FO_COPY ;Copies the files specified in the pFrom member to the location specified in the pTo member.
FO_DELET ;Deletes the files specified in pFrom. (pTo is ignored.)
FO_MOVE ;Moves the files specified in pFrom to the location specified in pTo.
FO_RENAME ;Renames the files specified in pFrom. ;

pFrom
Address of a buffer to specify one or more source file names. Multiple names must be null-separated. The list of names must be double null-terminated.
pTo
Address of a buffer to contain the name of the destination file or directory. The buffer can contain multiple destination file names if the fFlags member specifies FOF_MULTIDESTFILES. Multiple names must be null-separated. The list of names must be double null-terminated.
fFlags
Flags that control the file operation. This member can be a combination of the following flags: FOF_ALLOWUNDO ;Preserve Undo information, if possible. If pFrom does not contain fully qualified path and filenames, this flag is ignored. ;
FOF_CONFIRMMOUSE ;Not currently implemented. ;
FOF_FILESONLY ;Perform the operation on files only if a wildcard file name (*.*) is specified. ;
FOF_MULTIDESTFILES ;The pTo member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited. ;
FOF_NOCONFIRMATION ;Respond with Yes to All for any dialog box that is displayed. ;
FOF_NOCONFIRMMKDIR ;Does not confirm the creation of a new directory if the operation requires one to be created. ;
FOF_NOCOPYSECURITYATTRIBS ;Version 4.71. Microsoft® Windows NT® only. The security attributes of the file will not be copied. ;
FOF_NOERRORUI ;No user interface will be displayed if an error occurs. ;
FOF_RENAMEONCOLLISION ;Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. ;
FOF_SILENT ;Does not display a progress dialog box. ;
FOF_SIMPLEPROGRESS ;Displays a progress dialog box but does not show the file names. ;
FOF_WANTMAPPINGHANDLE ;If FOF_RENAMEONCOLLISION is specified, the hNameMappings member will be filled in if any files were renamed. ;

fAnyOperationsAborted
Value that receives TRUE if the user aborted any file operations before they were completed, or FALSE otherwise.
hNameMappings
Handle to a file name mapping object that contains an array of SHNAMEMAPPING structures. Each structure contains the old and new path names for each file that was moved, copied, or renamed. This member is used only if the fFlags member includes the FOF_WANTMAPPINGHANDLE flag. The handle must be freed by using the SHFreeNameMappings function.
lpszProgressTitle
Address of a string to use as the title of a progress dialog box. This member is used only if fFlags includes the FOF_SIMPLEPROGRESS flag.
If the pFrom or pTo members are unqualified names, the current directories are taken from the global current drive and directory settings as managed by theGetCurrentDirectory andSetCurrentDirectory functions.
 
[red][/red][:(]在win2000下是不能使用deltree/Y的!
 
直接调用是不行的。
但可以用批处理文件调用吧。

打开命令控制台,输入deltree/y 目录名,
应该可以删除的。
如果可以删除就能用执行批处理文件的方法,
如果不能删除就。。。。。
当我没说吧。
呵呵
 
我在winnt 下SHFileOperation删除文件夹就可以!不知道在win2000下行不行,我没测试过
 
procedure TForm1.BitBtn1Click(Sender: TObject);
var F:TShFileOpStruct; ; ;//uses shellapi;
; ; b:integer;
begin
; ;f.Wnd:=Form1.Handle;
; ;f.wFunc:=fo_delete; //fo_delete,copy,move,rename
; ;f.pFrom:=pChar(ExtractShortPathName('D:/Documents and Settings/Administrator/桌面/test'));
; ;//f.pTo:=pChar('c:/windows/desktop/new.txt');
; ;f.fFlags:={FOF_ALLOWUNDO or FOF_SILENT or} FOF_NOCONFIRMATION;
; ;b:=ShFileOperation(f);
; ;if f.fAnyOperationsAborted then ShowMessage('用户取消操作');
; ;if b=0 ;then exit;
; ;beep; ShowMessage('文件操作没有实现!');
end;
 
回 影子兄:你的答案我曾经试过,在win98下我已经成功过,可是在win2000下是没有deltree这个文件的,
我不可能把编好的文件加上从98下拷贝来的deltree.exe一起带来带去吧:-(
谢谢其他各位大侠的帮助,我在试一试,不懂会再问的,谢谢。

;
;
 
想不到没有DELTREE。
下面的可以实现不经回收站删除。
uses ShellAPI;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
; T:TSHfileOpStruct;

; P:String;
begin
; P:='g://test';//不知道为何,只有一个"/"时会出错(除非存在中文名)。
; with T do
; begin
; ; ;Wnd := 0;
; ; ;wFunc := FO_DELETE;
; ; ;pFrom := pchar(p);
; ; ;pTo := nil;
; ; ;fFlags := FOF_NOCONFIRMATION;
; end;
; SHFileOperation(T);
end;
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
439
import
I
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
后退
顶部