bourny Posted November 8, 2006 Posted November 8, 2006 Probably a simple one but I cannot figure it out without using external files to support it .. I would like to delete any file in a given directory or subdirectory with a given extention eg .test I can do this no probs for the current directory as FileFindFirstFile and Next file only work within the current directory but attempting to scan inside subdirectories seems a bit tricky .... any help appreciated ..
MadBoy Posted November 8, 2006 Posted November 8, 2006 Probably a simple one but I cannot figure it out without using external files to support it .. I would like to delete any file in a given directory or subdirectory with a given extention eg .test I can do this no probs for the current directory as FileFindFirstFile and Next file only work within the current directory but attempting to scan inside subdirectories seems a bit tricky .... any help appreciated .. You're right. It's a bit tricky I prepared you that script. Just change the names of variables to your case. And rest should be good expandcollapse popupDim $PATH_TO_DELETE = "C:\MyTest" Dim $DirData, $DirOutputOnce Dim $drivers_drive = StringMid($PATH_TO_DELETE, 1, 3) $DirOutput = Run(@ComSpec & " /c DIR /A:D /S " & $PATH_TO_DELETE, '', @SW_HIDE, 2) While 1 $DirData = StdoutRead($DirOutput) If @error Then ExitLoop If $DirData Then $DirOutputOnce &= $DirData Else Sleep(10) EndIf WEnd ; Remove spaces from output $DirOutputOnce = StringStripWS($DirOutputOnce, 3) ; Split output into array $DirSplit = StringSplit($DirOutputOnce, @CRLF, 1) For $i = 1 To $DirSplit[0] If StringInStr($DirSplit[$i], $PATH_TO_DELETE) Then $somestring = StringSplit($DirSplit[$i], $drivers_drive, 1) If $somestring[0] = 2 Then ; Testing amount of elements in array, if more then 2 Exits If StringInStr($drivers_drive & $somestring[2], $PATH_TO_DELETE) Then ; Making sure that Drivers path exists in string $drivers_directory = $drivers_drive & $somestring[2] $search_txt = $drivers_directory & "\*.test" $h_Search = FileFindFirstFile($search_txt) If $h_Search <> - 1 Then While 1 $file = FileFindNextFile($h_Search) If @error Then ExitLoop MsgBox(0, "File:", $drivers_directory & "\" & $file) FileDelete($drivers_directory & "\" & $file) WEnd EndIf FileClose($h_Search) EndIf EndIf EndIf Next My little company: Evotec (PL version: Evotec)
MHz Posted November 8, 2006 Posted November 8, 2006 You're right. It's a bit tricky ...Nice code. Since you used ComSpec, then I will too. $path = 'C:\MyTest\*.ext' Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE) ;FileFindFirstFile() ;FileFindNextFile() Oh, do not need the commented code.
bourny Posted November 8, 2006 Author Posted November 8, 2006 Thanks Madboy - looks good - I am having problems with the below code Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE, 2 ) - Removed the ,2 $DirOutputOnce &= $DirData - removed the extra & StdoutRead($DirOutput) - Where is this function Nice code. Since you used ComSpec, then I will too. $path = 'C:\MyTest\*.ext' Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE) ;FileFindFirstFile() ;FileFindNextFile() Oh, do not need the commented code.
ChrisL Posted November 8, 2006 Posted November 8, 2006 have a look here http://www.autoitscript.com/forum/index.ph...c=35595&hl= [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
MadBoy Posted November 8, 2006 Posted November 8, 2006 Thanks Madboy - looks good - I am having problems with the below code Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE, 2 ) - Removed the ,2$DirOutputOnce &= $DirData - removed the extra &StdoutRead($DirOutput) - Where is this functionMhz ) Nice code, mine was based on something else i just converted it from my other program. bourny: You have to use either My version or Mhz version. It seems you're trying to use both. If you're using mine don't remove & as it's needed there. I don't realy know what you're trying to change!! And why? My little company: Evotec (PL version: Evotec)
bourny Posted November 8, 2006 Author Posted November 8, 2006 Thanks to both ... Madboy - I copied your script out and the Scite script checker failed the script on my pointed out areas ... I have tried MHz 3 liner version seperatly and works no probs. Thanks to you both for your efforts and the answer to my question .. Bourny
MHz Posted November 8, 2006 Posted November 8, 2006 Thanks to you both for your efforts and the answer to my question ..No problem. If you wanted the StdOut for any reason, then this would do it. Global $data, $pid = Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE, 2) Do $data &= StdoutRead($pid) Until @error MsgBox(0, '', $data)
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