function GetDirectory: String;<br>begin<br> if not SelectDirectory(Result, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then<br> Result := EmptyStr;<br>end;<br><br>procedure CopyDirectoryTree(AHandle: THandle; const AFromDirectory, AToDirectory: String);<br>var<br> SHFileOpStruct: TSHFileOpStruct;<br> FromDir: PChar;<br> ToDir: PChar;<br>begin<br><br> GetMem(FromDir, Length(AFromDirectory)+2);<br> try<br> GetMem(ToDir, Length(AToDirectory)+2);<br> try<br><br> FillChar(FromDir^, Length(AFromDirectory)+2, 0);<br> FillChar(ToDir^, Length(AToDirectory)+2, 0);<br><br> StrCopy(FromDir, PChar(AFromDirectory));<br> StrCopy(ToDir, PChar(AToDirectory));<br><br> with SHFileOpStruct do<br> begin<br> Wnd := AHandle; // Assign the window handle<br> wFunc := FO_COPY; // Specify a file copy<br> pFrom := FromDir;<br> pTo := ToDir;<br> fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;<br> fAnyOperationsAborted := False;<br> hNameMappings := nil;<br> lpszProgressTitle := nil;<br> if SHFileOperation(SHFileOpStruct) <> 0 then<br> RaiseLastWin32Error;<br> end;<br> finally<br> FreeMem(ToDir, Length(AToDirectory)+2);<br> end;<br> finally<br> FreeMem(FromDir, Length(AFromDirectory)+2);<br> end;<br>end;<br><br>procedure ToRecycle(AHandle: THandle; const ADirName: String);<br>var<br> SHFileOpStruct: TSHFileOpStruct;<br> DirName: PChar;<br> BufferSize: Cardinal;<br>begin<br> BufferSize := Length(ADirName) +1 +1;<br> GetMem(DirName, BufferSize);<br> try<br> FillChar(DirName^, BufferSize, 0);<br> StrCopy(DirName, PChar(ADirName));<br><br> with SHFileOpStruct do<br> begin<br> Wnd := AHandle;<br> wFunc := FO_DELETE;<br> pFrom := DirName;<br> pTo := nil;<br> fFlags := FOF_ALLOWUNDO;<br><br> fAnyOperationsAborted := False;<br> hNameMappings := nil;<br> lpszProgressTitle := nil;<br> end;<br><br> if SHFileOperation(SHFileOpStruct) <> 0 then<br> RaiseLastWin32Error;<br> finally<br> FreeMem(DirName, BufferSize);<br> end;<br>end;<br><br>procedure TMainForm.spbtnGetFromDirClick(Sender: TObject);<br>begin<br> edtFromDir.Text := GetDirectory;<br>end;<br><br>procedure TMainForm.spbtnGetToDirClick(Sender: TObject);<br>begin<br> edtToDir.Text := GetDirectory;<br>end;<br><br>procedure TMainForm.btnCopyDirectoryClick(Sender: TObject);<br>begin<br> CopyDirectoryTree(Handle, edtFromDir.Text, edtToDir.Text);<br>end;<br><br>procedure TMainForm.spbtnRecycleBinClick(Sender: TObject);<br>begin<br> edtRecycleDir.Text := GetDirectory;<br>end;<br><br>procedure TMainForm.btnRecycleDirClick(Sender: TObject);<br>begin<br> ToRecycle(0, edtRecycleDir.Text);<br>end;<br><br>procedure TMainForm.btnCloseClick(Sender: TObject);<br>begin<br> Close;<br>end;<br><br>end.<br>