|
Вопрос # 1 076/ вопрос открыт / |
|
Здравствуйте!
Как программно удалить из корзины одну нужную папку?
 |
Вопрос задал: Ilia Ermakov (статус: 1-ый класс)
Вопрос отправлен: 2 ноября 2007, 20:03
Состояние вопроса: открыт, ответов: 1.
|
Ответ #1. Отвечает эксперт: Feniks
Здравствуйте, Ilia Ermakov!
В Приложении несколько примеров по работе с корзиной:
1. Восстановление файла из корзины.
2. Как удалить/восстановить файлы из корзины?
3. Просмотр состояния корзины.
4. Очистка корзины.
Приложение: Переключить в обычный режим-
-
-
- function RestoreElement(const AHandle: THandle; LV: TListView): Boolean;
-
- function GetLVItemText(const Index: Integer): String;
- begin
- if Index = 0 then
- Result := LV.Selected.Caption
- else
- Result := LV.Selected.SubItems.Strings[Index - 1];
- end;
-
- var
- ppidl, Item: PItemIDList;
- Desktop: IShellFolder;
- RecycleBin: IShellFolder2;
- RecycleBinEnum: IEnumIDList;
- Fetched, I: Cardinal;
- Details: TShellDetails;
- Mallok: IMalloc;
- Valid: Boolean;
- Context: IContextMenu;
- AInvokeCommand: TCMInvokeCommandInfo;
- begin
- Result := False;
- if LV = nil then Exit;
- if SHGetMalloc(Mallok) = S_OK then
- if SHGetSpecialFolderLocation(AHandle, CSIDL_BITBUCKET, ppidl) = S_OK then
- if SHGetDesktopFolder(Desktop) = S_OK then
- if Desktop.BindToObject(ppidl, nil, IID_IShellFolder2, RecycleBin) = S_OK then
- if RecycleBin.EnumObjects(AHandle,
- SHCONTF_FOLDERS or SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN, RecycleBinEnum) = S_OK
then
- begin
-
- while True do
- begin
- RecycleBinEnum.Next(1, Item, Fetched);
- if Fetched = 0 then Break;
- Valid := False;
- for I := 0 to DETAIL_COUNT - 1 do
- if RecycleBin.GetDetailsOf(Item, I, Details) = S_OK then
- try
-
- Valid := GetLVItemText(I) = StrRetToString(Item, Details.str);
- if not Valid then Break;
- finally
- Mallok.Free(Details.str.pOleStr);
- end;
-
- if Valid then
- begin
-
- if RecycleBin.GetUIObjectOf(AHandle, 1, Item,
- IID_IContextMenu, nil, Pointer(Context)) = S_OK then
- begin
- FillMemory(@AInvokeCommand, SizeOf(AInvokeCommand), 0);
- with AInvokeCommand do
- begin
- cbSize := SizeOf(AInvokeCommand);
- hwnd := AHandle;
-
-
-
-
- fMask := 0;
- lpDirectory := PChar(LV.Selected.SubItems.Strings[0]);
- nShow := SW_SHOWNORMAL;
- end;
- Result := Context.InvokeCommand(AInvokeCommand) = S_OK;
- Break;
- end;
- end;
- end;
- end;
- end;
-
- procedure TForm1.mnuRestoreClick(Sender: TObject);
- begin
- if ListView1.Selected <> nil then
-
- end;
-
-
-
-
-
-
-
- <code>program del;
-
- uses
- ShellApi;
-
- //function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer; stdcall;
-
- var
- T: TSHFileOpStruct;
- P: string;
- begin
- P := 'C:WindowsSystemEL_CONTROL.CPL';
- with T do
- begin
- Wnd := 0;
- wFunc := FO_DELETE;
- pFrom := Pchar(P);
- fFlags := FOF_ALLOWUNDO
- end;
- SHFileOperation(T);
- end.
-
-
-
-
-
-
- var
- FileList: string;
- FOS: TShFileOpStruct;
- begin
- FileList := 'c:delete.me'#0'c:windowstemp.$$$'#0#0;
-
- FileList := Filename1 + #0 + Filename2 + #0#0;
- FOS.pFrom := PChar(FileList);
-
- end;
-
-
-
-
- unit Unit1;
-
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ShellAPI;
-
- const
- SHERB_NOCONFIRMATION = $1;
- SHERB_NOPROGRESSUI = $2;
- SHERB_NOSOUND = $4;
-
- type
- TForm1 = class(TForm)
- btnGetRecicleBinFileCount: TButton;
- btnEmptyRecicleBin: TButton;
- btnDelToReciclebin: TButton;
- procedure btnGetRecicleBinFileCountClick(Sender: TObject);
- procedure btnEmptyRecicleBinClick(Sender: TObject);
- procedure btnDelToReciclebinClick(Sender: TObject);
- end;
-
- type
- TSHQueryRBInfo = packed record
- cbSize : DWORD;
- i64Size,
- i64NumItems : TLargeInteger;
- end;
- PSHQueryRBInfo = ^TSHQueryRBInfo;
-
- function SHEmptyRecycleBin(hwnd: HWND; pszRootPath: PChar;
- dwFlags: DWORD): HRESULT; stdcall;
- external 'shell32.dll' name 'SHEmptyRecycleBinA';
-
- function SHQueryRecycleBin (pszRootPath: PChar;
- var SHQueryRBInfo: TSHQueryRBInfo): HRESULT; stdcall;
- external 'Shell32.dll' name 'SHQueryRecycleBinA';
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.dfm}
-
-
- procedure TForm1.btnGetRecicleBinFileCountClick(Sender: TObject);
- var
- Info: TSHQueryRBInfo;
- Err: HRESULT;
- begin
- ZeroMemory(@Info, SizeOf(Info));
- Info.cbSize := SizeOf(Info);
- Err := SHQueryRecycleBin(nil, Info);
- if Err = S_OK then
-
- [Info.i64NumItems, Info.i64Size]))
- else
- ShowMessage(SysErrorMessage(Err));
- end;
- end.
-
-
-
-
-
- unit Unit1;
-
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ShellAPI;
-
- const
- SHERB_NOCONFIRMATION = $1;
- SHERB_NOPROGRESSUI = $2;
- SHERB_NOSOUND = $4;
-
- type
- TForm1 = class(TForm)
- btnGetRecicleBinFileCount: TButton;
- btnEmptyRecicleBin: TButton;
- btnDelToReciclebin: TButton;
- procedure btnGetRecicleBinFileCountClick(Sender: TObject);
- procedure btnEmptyRecicleBinClick(Sender: TObject);
- procedure btnDelToReciclebinClick(Sender: TObject);
- end;
-
- type
- TSHQueryRBInfo = packed record
- cbSize : DWORD;
- i64Size,
- i64NumItems : TLargeInteger;
- end;
- PSHQueryRBInfo = ^TSHQueryRBInfo;
-
- function SHEmptyRecycleBin(hwnd: HWND; pszRootPath: PChar;
- dwFlags: DWORD): HRESULT; stdcall;
- external 'shell32.dll' name 'SHEmptyRecycleBinA';
-
- function SHQueryRecycleBin (pszRootPath: PChar;
- var SHQueryRBInfo: TSHQueryRBInfo): HRESULT; stdcall;
- external 'Shell32.dll' name 'SHQueryRecycleBinA';
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.dfm}
-
-
- procedure TForm1.btnEmptyRecicleBinClick(Sender: TObject);
- var
- Err: HRESULT;
- begin
- Err := SHEmptyRecycleBin(Handle, 'c:', SHERB_NOSOUND);
- if Err <> S_OK then ShowMessage(SysErrorMessage(Err));
- end;
- end.
-
-
-
 |
Ответ отправил: Feniks (статус: Бакалавр)
Время отправки: 5 ноября 2007, 10:54
|
Мини-форум вопроса
Всего сообщений: 1; последнее сообщение — 2 ноября 2007, 20:17; участников в обсуждении: 1.
|
Косолапов Дмитрий Юрьевич (статус: 8-ой класс), 2 ноября 2007, 20:17 [#1]:
Ну так как Корзина - это не что иное, как папка на соответствущем диске (RECYCLER в XP и, наверное, в еще каких-то, а в Win9x RECYCLED, насколько я помню), то надо непосредственно удалить соответствующую папку.
|
Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.
|