Terenz Posted January 13, 2014 Share Posted January 13, 2014 (edited) Hello guys, I need to put a file to the trash This file is on a network path so if i'll delete the file was delete permenently, without going to the recycle. So i have say, "I'll do it in autoit, how hard it can be?" Well is hard, at least for me What i have try: a ) FileMove, not work. On XP ( also on 7, with a different name but for now i'll check on this os ) there is a folder for the recycle in: C:RECYCLERMany number-letter So i have try to move the file in this folder, nothing b ) FileRecycle, not work c ) SHFileOperationW, the same Maybe someone has a better idea, my ( not working ) code: expandcollapse popupGlobal Const $FO_DELETE = 0x0003 Global Const $FOF_ALLOWUNDO = 0x0040 Global Const $FOF_NOCONFIRMATION = 0x0010 Global Const $FOF_NOCONFIRMMKDIR = 0x0200 Global Const $FOF_NOERRORUI = 0x0400 Global Const $FOF_SILENT = 0x0004 Global Const $FOF_NO_UI = BitOR($FOF_NOCONFIRMATION, $FOF_NOCONFIRMMKDIR, $FOF_NOERRORUI, $FOF_SILENT) Global Const $tagSHFILEOPSTRUCT = 'hwnd hWnd;uint Func;ptr From;ptr To;dword Flags;int fAnyOperationsAborted;ptr hNameMappings;ptr ProgressTitle;' Local $Search, $RecycleBin $MyFile = FileOpen(@ScriptDir & "\Test.txt", 2) FileClose($MyFile) If FileExists(@HomeDrive & "\RECYCLER") Then $Search = FileFindFirstFile(@HomeDrive & "\RECYCLER\*.*") If $Search <> -1 Then $RecycleBin = @HomeDrive & "\RECYCLER\" & FileFindNextFile($Search) ConsoleWrite("RECYCLER: " & $RecycleBin & @CRLF) ;~ FileRecycle(@ScriptDir & "\Test.txt") ;~ FileMove(@ScriptDir & "\Test.txt", $RecycleBin) ;~ _WinAPI_ShellFileOperation(@ScriptDir & "\Test.txt", '', $FO_DELETE, BitOR($FOF_ALLOWUNDO, $FOF_NO_UI)) EndIf EndIf Func _WinAPI_ShellFileOperation($sFrom, $sTo, $iFunc, $iFlags, $sTitle = '', $hParent = 0) Local $tFrom, $tTo, $Data If Not IsArray($sFrom) Then $Data = $sFrom Dim $sFrom[1] = [$Data] EndIf $tFrom = _WinAPI_ArrayToStruct($sFrom) If @error Then Return SetError(-1, 0, 0) EndIf If Not IsArray($sTo) Then $Data = $sTo Dim $sTo[1] = [$Data] EndIf $tTo = _WinAPI_ArrayToStruct($sTo) If @error Then Return SetError(-1, 0, 0) EndIf Local $tSHFILEOPSTRUCT = DllStructCreate($tagSHFILEOPSTRUCT) DllStructSetData($tSHFILEOPSTRUCT, 'hWnd', $hParent) DllStructSetData($tSHFILEOPSTRUCT, 'Func', $iFunc) DllStructSetData($tSHFILEOPSTRUCT, 'From', DllStructGetPtr($tFrom)) DllStructSetData($tSHFILEOPSTRUCT, 'To', DllStructGetPtr($tTo)) DllStructSetData($tSHFILEOPSTRUCT, 'Flags', $iFlags) DllStructSetData($tSHFILEOPSTRUCT, 'ProgressTitle', $sTitle) Local $Ret = DllCall('shell32.dll', 'int', 'SHFileOperationW', 'ptr', DllStructGetPtr($tSHFILEOPSTRUCT)) If @error Then Return SetError(-1, 0, 0) Else If $Ret[0] Then Return SetError($Ret[0], 0, 0) EndIf EndIf Return $tSHFILEOPSTRUCT EndFunc ;==>_WinAPI_ShellFileOperation Func _WinAPI_ArrayToStruct(Const ByRef $aData, $iStart = 0, $iEnd = -1) If Not IsArray($aData) Then Return SetError(2, 0, 0) EndIf Local $tData, $Count, $Struct = '' If $iStart < 0 Then $iStart = 0 EndIf If ($iEnd < 0) Or ($iEnd > UBound($aData) - 1) Then $iEnd = UBound($aData) - 1 EndIf For $i = $iStart To $iEnd $Struct &= 'wchar[' & (StringLen($aData[$i]) + 1) & '];' Next $tData = DllStructCreate($Struct & 'wchar[1]') If @error Then Return SetError(1, 0, 0) EndIf $Count = 1 For $i = $iStart To $iEnd DllStructSetData($tData, $Count, $aData[$i]) $Count += 1 Next DllStructSetData($tData, $Count, ChrW(0)) Return $tData EndFunc ;==>_WinAPI_ArrayToStruct Thanks for any help Edited January 13, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
KaFu Posted January 13, 2014 Share Posted January 13, 2014 Seems to be this way by design. Here's a workaround described that sends the files to the local bin, not the server bin though ("Not entirely true."). http://social.technet.microsoft.com/Forums/windowsserver/en-US/7119aafa-fe55-470c-ae20-568b80c5dcb4/files-deleting-over-the-network-share-drive-is-not-going-to-the-recycle-bin-it-permanently-delete?forum=winservergen OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now