VelvetElvis Posted February 11, 2013 Share Posted February 11, 2013 I'm trying to delete all files and folders (names unknown) within a folder. I can delete the files of course, but don't know how to easily delete folders (without writing recursion routines or capturing folders to an array, etc.) I tried DirRemove(), but it deletes the folder specified as well. How can I easily delete all the folders under a specific location? E.g: Top folder --- --- Unknown folder 1 --- Unknown folder 2 Delete folders within "Top folder", but not remove "Top folder." Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 11, 2013 Moderators Share Posted February 11, 2013 VelvetElvis,Use FileListToArray to get a list of files and folders within the "Top folder" - then loop through the returned array(s) and delete each one found. 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...
Moderators JLogan3o13 Posted February 11, 2013 Moderators Share Posted February 11, 2013 (edited) Check out Melba's _RecFileListToArray (). You could set the third parameter to folders only, then do something simple like this:#include <Array.au3> #include <RecFileListToArray.au3> $aArray = _RecFileListToArray("C:\", "*", 2, 0, 1, 0) For $i = 1 To $aArray[0] DirRemove($aArray[$i], 1) NextEdit: Too slow Edited February 11, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
VelvetElvis Posted February 11, 2013 Author Share Posted February 11, 2013 Thanks folks! I was hoping I'd missed something with DirRemove(). FileListToArray() it is. Link to comment Share on other sites More sharing options...
forever0donotknowme Posted February 11, 2013 Share Posted February 11, 2013 for delete folders and files from temp folder I will give you example for deleting all folders and files in temp folder #include <Array.au3> #include <RecFileListToArray.au3> $aArray = _RecFileListToArray(@temp, "*", 2, 0, 1, 0) For $i = 1 To $aArray[0] DirRemove($aArray[$i], 1) Next Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 11, 2013 Moderators Share Posted February 11, 2013 (edited) for delete folders and files from temp folder I will give you example for deleting all folders and files in temp folderYou copied exactly what I had in Post #3. You even used the same array name. What value do you think that brings to the OP? Edited February 11, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
forever0donotknowme Posted February 11, 2013 Share Posted February 11, 2013 If really you post that you should explain task for following numbers 2,0,1,0 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 11, 2013 Moderators Share Posted February 11, 2013 forever0donotknowme,I had just removed your "Permanent Mod queue" restriction after your last rush of blood to the head and here you are misbehaving again. Carry on like this and more serious sanctions will be imposed. 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...
forever0donotknowme Posted February 11, 2013 Share Posted February 11, 2013 melba my sir I am very expert but I look as crazy in oreder to let you feel laughing Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 11, 2013 Moderators Share Posted February 11, 2013 Not to completely derail the thread, but I still say this guy is trolling. I don't believe the "language barrier" for a moment, it is inconsistent. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Developers Jos Posted February 11, 2013 Developers Share Posted February 11, 2013 (edited) Doubt that answer does you any favours.... This was for forever0donotknowme Edited February 11, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Trong Posted February 15, 2013 Share Posted February 15, 2013 (edited) Delete all files/folders inside it:$iReturn = _FindDelAll(@TempDir) ;~ $iReturn = _FindDelAll("C:\Temp", 1) If $iReturn = 1 Then ConsoleWrite(" Success! " & @CRLF) ElseIf $iReturn = 0 Then ConsoleWrite(" Error! " & @CRLF) Else ConsoleWrite(" The path is not valid! " & @CRLF) EndIfRemove folder is simple:_RemoveDir("C:\Temp") ; Or _FindDelAll("C:\Temp", 1)Function: expandcollapse popupFunc _FindDelAll($zSearchDir, $zRemoveSearchDir = 0) ; /*********************************************************************** * ; * ---:| Function : _FindDelAll ; * ---:| Author : Anonimajn ; ************************************************************************ * Local $zRSD = Number($zRemoveSearchDir) If Not FileExists($zSearchDir) Or Not StringInStr(FileGetAttrib($zSearchDir), "D") Then Return Number(-1) Else If $zRSD <> 1 Then If StringRight($zSearchDir, 1) <> "\" Then $zSearchDir &= "\" Dim $xSearch, $sFile $xSearch = FileFindFirstFile($zSearchDir & "*") If $xSearch <> -1 Then While 1 $sFile = FileFindNextFile($xSearch) If @error Then ExitLoop If StringInStr(FileGetAttrib($zSearchDir & $sFile), "D") Then _RemoveDir($zSearchDir & $sFile) Else _DelFile($zSearchDir & $sFile) EndIf WEnd Else FileClose($xSearch) Return Number(0) EndIf FileClose($xSearch) Return Number(1) EndIf If $zRSD = 1 Then _RemoveDir($zSearchDir) If Not FileExists($zSearchDir) Then Return Number(1) Else Return Number(0) EndIf EndIf EndIf EndFunc ;==>_FindDel Func _DelFile($sFilePath) ; /*********************************************************************** * ; * ---:| Function : _DelFile ; * ---:| Author : Anonimajn ; ************************************************************************ * If Not FileExists($sFilePath) Or StringInStr(FileGetAttrib($sFilePath), "D") Then Return Number(-1) Else FileSetAttrib($sFilePath, "-RASH") FileDelete($sFilePath) If FileExists($sFilePath) Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFilePath & '" /G EveryOne:F', '', @SW_HIDE) If FileExists($sFilePath) Then FileDelete($sFilePath) If FileExists($sFilePath) Then Return Number(0) Else Return Number(1) EndIf EndIf EndFunc ;==>_DelFile Func _RemoveDir($sFolder) ; /*********************************************************************** * ; * ---:| Function : _RemoveDir ; * ---:| Author : Anonimajn ; ************************************************************************ * If FileExists($sFolder) And StringInStr(FileGetAttrib($sFolder), "D") And StringLen($sFolder) > 3 Then FileSetAttrib($sFolder, "-RSH", 1) DirRemove($sFolder, 1) If FileExists($sFolder) Then RunWait(@ComSpec & ' /c RD /s /q "' & $sFolder & '"', "", @SW_HIDE) If FileExists($sFolder) Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFolder & '" /G EveryOne:F & RD /s /q "' & $sFolder & '"', '', @SW_HIDE) If FileExists($sFolder) Then DirRemove($sFolder, 1) If FileExists($sFolder) Then Return Number(0) Else Return Number(1) EndIf Else Return Number(-1) EndIf EndFunc ;==>_RemoveDir Edited February 15, 2013 by Trong Regards, 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