Borje Posted September 12, 2008 Share Posted September 12, 2008 Is there anybody can help me I placed this code in a program before I exit the program when ended the program FileDelete(@TempDir & "\Test.ini") FileDelete (@TempDir & "\English.lng") DirRemove (@TempDir & "\Test",1) Exit When I run my code and when I Exit the code I want this to work.. Sometimes it works but not every time why ? Link to comment Share on other sites More sharing options...
Andreik Posted September 12, 2008 Share Posted September 12, 2008 Is there anybody can help me I placed this code in a program before I exit the program when ended the program FileDelete(@TempDir & "\Test.ini") FileDelete (@TempDir & "\English.lng") DirRemove (@TempDir & "\Test",1) ExitWhen I run my code and when I Exit the code I want this to work.. Sometimes it works but not every time why ?Try with @error to see if you get an error. Link to comment Share on other sites More sharing options...
Borje Posted September 12, 2008 Author Share Posted September 12, 2008 Thanks Andreik I have try the @Error but I have no error and it still not working. Link to comment Share on other sites More sharing options...
picaxe Posted September 12, 2008 Share Posted September 12, 2008 TryWhile Not FileDelete(@TempDir & "\Test.ini") Sleep(100) WEnd While Not FileDelete(@TempDir & "\English.lng") Sleep(100) WEnd While Not DirRemove (@TempDir & "\Test",1) Sleep(100) WEnd Link to comment Share on other sites More sharing options...
Andreik Posted September 12, 2008 Share Posted September 12, 2008 (edited) Thanks Andreik I have try the @Error but I have no error and it still not working. Do a simple test. Check with FileExists() if the file exist. And then something like this: While FileExists(@TempDir & "\Test.ini") Then FileDelete(@TempDir & "\Test.ini") Wend EDIT: Or you can use DOS: #include <Process.au3> _RunDOS('del "' & @TempDir & '\Test.ini' & '"') Hope that helps and work fine. Edited September 12, 2008 by Andreik Link to comment Share on other sites More sharing options...
Borje Posted September 12, 2008 Author Share Posted September 12, 2008 Thanks Picaxe I have try but first time it works but when I run second time it not works that freese and I must open taskmanager and stop the process Link to comment Share on other sites More sharing options...
Borje Posted September 12, 2008 Author Share Posted September 12, 2008 Andreik _RunDOS('del "' & @TempDir & '\Test.ini' & '"') that not works Link to comment Share on other sites More sharing options...
picaxe Posted September 12, 2008 Share Posted September 12, 2008 (edited) Ok I should have put in some proper error checking and a timeout, try this $sDir = @TempDir $sFiles = "Test.ini,English.lng,\Test" $aFiles = StringSplit($sFiles, ",") For $j = 1 To $aFiles[0] $i = 50 While $i > 0 If StringLeft($aFiles[$j], 1) = "\" Then If DirRemove($sDir & $aFiles[$j]) Then ExitLoop If FileExists($sDir & $aFiles[$j] & "\*.*") Then If Not FileDelete($sDir & $aFiles[$j] & "\*.*") Then MsgBox(262160, "Delete Error", "Error deleting files in folder " & $aFiles[$j]) ExitLoop EndIf EndIf Else If FileDelete($sDir & '\' & $aFiles[$j]) Then ExitLoop EndIf Sleep(100) $i -= 1 If $i = 0 Then MsgBox(262160, "Delete Error", "Error deleting " & $aFiles[$j] & " @error=" & @error) ExitLoop EndIf WEnd NextEither a file must still be open or being accessed by your AutoIt app or some other app or folder Test is not empty. Edited September 12, 2008 by picaxe Link to comment Share on other sites More sharing options...
trancexx Posted September 12, 2008 Share Posted September 12, 2008 Could be just file/folder attribute. Check it, and change it before deleting ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
silver217 Posted December 2, 2011 Share Posted December 2, 2011 I am also struggling with this I am writing a program that keeps a directory size below a limit by deleting the oldest file: while dirgetsize($targetdir) > $max find the oldest file $fold filedelete($fold) wend the oldest file does not get deleted this way, it is still there. I checked attributes. Why is this such a problem ? Anybody has a suggestion ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2011 Moderators Share Posted December 2, 2011 silver217, Can you please post the full code you have tried - your logic seems fine so it might be a syntax problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
silver217 Posted December 2, 2011 Share Posted December 2, 2011 (edited) I don't know how to put code in this forum as a popup so here it is as text: expandcollapse popupWhile 1 dodir($targetdir) tolog("=====================================================") tolog('fold = ' & $fold) $d = InputBox('Delete ?', $fold & @CRLF & $attrib & @CRLF & $tz) If $d <> 1 Then Exit Else tolog($attrib) If $attrib = ' Directory' Then ; DirRemove($fold) Else While Not FileDelete($fold) Sleep(100) WEnd EndIf EndIf WEnd ; log_to_screen() Exit Func dodir($p) FileChangeDir($p) ;tolog("dir: " & @WorkingDir) $search = FileFindFirstFile("*.*") If $search = -1 Then ; tolog(" Empty dir !") ; Exit ; EndIf Else While 1 $file = FileFindNextFile($search) If @error Then ExitLoop ; tolog($file) If StringInStr(FileGetAttrib($file), "S") Or StringInStr(FileGetAttrib($file), "H") Or StringInStr(FileGetAttrib($file), "D") Then ; tolog("S H or Dir: " & $file) EndIf If StringInStr(FileGetAttrib($file), "D") Then gosub($file) $t = FileGetTime($file, 0, 1) ; date modified = 0 If $t < $oo Then $oo = $t $fold = $p & '' & $file EndIf WEnd EndIf FileClose($search) ;tolog("dir: " & @WorkingDir) ;tolog("--------------------------------------------------------") $attrib = FileGetAttrib($fold) If @error Then ; tolog('Error: Could not obtain attributes of oldest file: ' & $fold) Else $input = StringSplit("R,A,S,H,N,D,O,C,T", ",") $output = StringSplit("Read-only /, Archive /, System /, Hidden /" & _ ", Normal /, Directory /, Offline /, Compressed /, Temporary /", ",") For $i = 1 To 9 $attrib = StringReplace($attrib, $input[$i], $output[$i], 0, 1) ; last parameter in StringReplace means case-sensitivity Next $attrib = StringTrimRight($attrib, 2) ;remove trailing slash ; tolog("oldest: " & $fold & ", attributes: " & $attrib) EndIf EndFunc ;==>dodir Func gosub($sub) ;tolog('subdir: ' & $sub) $oldwd = @WorkingDir dodir(@WorkingDir & "" & $sub) FileChangeDir($oldwd) EndFunc ;==>gosub Edited December 3, 2011 by silver217 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2011 Moderators Share Posted December 2, 2011 silver217, I don't know how to put code in this forum as a popupYou put [autoit] before and [/autoit] after your code - which I am looking at now. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted December 2, 2011 Share Posted December 2, 2011 silver217, Can you post the COMPLETE code? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2011 Moderators Share Posted December 2, 2011 silver217,I am not debugging that code - it is incomplete and I hate debugging recursive calls to FileFindFirst/NextFile. Please read the Recursion tutorial in the Wiki to see why - and to find out a better way to do it. Here is a function I just threw together using my RecFileListToArray UDF (look in my sig for the link). I have tested it a few times and it seems to work fine:expandcollapse popup#include <RecfileListToArray.au3> #include <Array.au3> ; Set the root path $sRoot = "N:Sizer" ; Get a list of files including in subdirs with full path $aFileList = _RecFileListToArray($sRoot, "*", 1, 1, 0, 2) ; Now create an array of the filetimes and fill it Global $aTimes[$aFileList[0] + 1] = [$aFileList[0]] For $i = 1 To $aFileList[0] $aTimes[$i] = Number(FileGetTime($aFileList[$i], 0, 1)) Next ; Just for testing _ArrayDisplay($aFileList, "Start") _ArrayDisplay($aTimes, "Start") ; This is the folder size at the start MsgBox(0, "Initial Size", DirGetSize($sRoot)) ; Set a suitable size here While DirGetSize($sRoot) > 20000000 ; Reset the initial values $iOldest = 99999999999999 $sOldest = "" $iIndex = 0 ; Now go through the times to find the oldest For $i = 1 To $aTimes[0] If $aTimes[$i] < $iOldest Then $iOldest = $aTimes[$i] $sOldest = $aFileList[$i] $iIndex = $i EndIf Next ; And delete the file FileDelete($sOldest) ; Make sure it has gone Do Sleep(10) Until Not FileExists($sOldest) ; And remove it from the arrays _ArrayDelete($aFileList, $iIndex) $aFileList[0] -= 1 _ArrayDelete($aTimes, $iIndex) $aTimes[0] -= 1 ; Just to check _ArrayDisplay($aFileList, "In loop") WEnd ; And this is the folder size at the end MsgBox(0, "Final Size", DirGetSize($sRoot))It should not be too hard to amend it to fit your script, but do come back if you run into problems. M23 silver217 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
silver217 Posted December 3, 2011 Share Posted December 3, 2011 Thank you M23, for telling me to and the link to the recursion tutorial. I think I can solve it now. Link to comment Share on other sites More sharing options...
silver217 Posted December 3, 2011 Share Posted December 3, 2011 one last question ? Where can I find <RecfileListToArray.au3> Link to comment Share on other sites More sharing options...
KaFu Posted December 3, 2011 Share Posted December 3, 2011 In Melba23's signature ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 3, 2011 Moderators Share Posted December 3, 2011 (edited) silver217, I did tell you in the post above: my RecFileListToArray UDF (look in my sig for the link)Or you can go directly to it by clicking here. M23 Edit: Added direct link. Edited December 3, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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