mdwerne Posted April 7, 2011 Share Posted April 7, 2011 Can anyone with a better grasp of AutoIt see my mistake/s? #include <File.au3> Local $i ;Local $data = @HomeDrive & "\Dir1"|@HomeDrive & "\Dir2"|@HomeDrive & "\Dir3"|@HomeDrive & "\Dir4" Local $data = '@HomeDrive & "\Dir1"|@HomeDrive & "\Dir2"|@HomeDrive & "\Dir3"|@HomeDrive & "\Dir4"' Local $arr = StringSplit($data, "|") For $i = 1 To $arr[0] Local $DelDir = DirRemove($arr[$i], 1) MsgBox("", "Result", $DelDir) If $DelDir = 1 Then ConsoleWrite($arr[$i] & @LF) _FileWriteLog(@HomeDrive & "\Delete.log", " Directory " & $arr[$i] & " was removed") EndIf Next I'm guessing it's in my $data variable, but I'm not sure what the correct syntax is... Thanks for your time, -Mike Link to comment Share on other sites More sharing options...
smartee Posted April 7, 2011 Share Posted April 7, 2011 Your guess was right here's what it should beLocal $data = @HomeDrive & "\Dir1|" & @HomeDrive & "\Dir2|" & @HomeDrive & "\Dir3|" & @HomeDrive & "\Dir4" Link to comment Share on other sites More sharing options...
guinness Posted April 7, 2011 Share Posted April 7, 2011 (edited) Declaring a variable can slow down the Loop, best to declare outside of the For..Next Loop. And if you want the harder way >> #include <File.au3> Local $sData = '@HomeDrive & "\Dir1"|@HomeDrive & "\Dir2"|@HomeDrive & "\Dir3"|@HomeDrive & "\Dir4"' Local $aArray = StringSplit($sData, "|"), $iDelete For $i = 1 To $aArray[0] $aArray[$i] = StringReplace($aArray[$i], "@HomeDrive", @HomeDrive) $aArray[$i] = StringReplace($aArray[$i], '"', "") $aArray[$i] = StringReplace($aArray[$i], ' & ', "") $aArray[$i] = StringStripWS($aArray[$i], 7) ConsoleWrite($aArray[$i] & @CRLF) $iDelete = DirRemove($aArray[$i], 1) If $iDelete = 1 Then ConsoleWrite($aArray[$i] & @LF) ;~ _FileWriteLog(@HomeDrive & "\Delete.log", " Directory " & $arr[$i] & " was removed") EndIf Next But honestly why not use an Array like >> $aArray[3] = [3, @HomeDrive & "\Dir1", @HomeDrive & "\Dir2", @HomeDrive & "\Dir3"] Edited April 7, 2011 by guinness UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mdwerne Posted April 7, 2011 Author Share Posted April 7, 2011 Your guess was right here's what it should beLocal $data = @HomeDrive & "\Dir1|" & @HomeDrive & "\Dir2|" & @HomeDrive & "\Dir3|" & @HomeDrive & "\Dir4" Yep, works perfect, thank you!! -Mike Link to comment Share on other sites More sharing options...
mdwerne Posted April 7, 2011 Author Share Posted April 7, 2011 (edited) Declaring a variable can slow down the Loop, best to declare outside of the For..Next Loop. And if you want the harder way >> #include <File.au3> Local $sData = '@HomeDrive & "\Dir1"|@HomeDrive & "\Dir2"|@HomeDrive & "\Dir3"|@HomeDrive & "\Dir4"' Local $aArray = StringSplit($sData, "|"), $iDelete For $i = 1 To $aArray[0] $aArray[$i] = StringReplace($aArray[$i], "@HomeDrive", @HomeDrive) $aArray[$i] = StringReplace($aArray[$i], '"', "") $aArray[$i] = StringReplace($aArray[$i], ' & ', "") $aArray[$i] = StringStripWS($aArray[$i], 7) ConsoleWrite($aArray[$i] & @CRLF) $iDelete = DirRemove($aArray[$i], 1) If $iDelete = 1 Then ConsoleWrite($aArray[$i] & @LF) ;~ _FileWriteLog(@HomeDrive & "\Delete.log", " Directory " & $arr[$i] & " was removed") EndIf Next But honestly why not use an Array like >> $aArray[3] = [3, @HomeDrive & "\Dir1", @HomeDrive & "\Dir2", @HomeDrive & "\Dir3"] So the hard way I think is above my grade...your way of doing an array seems very cool,but my array is actually a 100 or so directories and keeps growing so I didn't want to define the number of elements. Here is my stab at it... $Array = StringSplit(@HomeDrive & "\Dir1", @HomeDrive & "\Dir2", @HomeDrive & "\Dir3", @HomeDrive & "\Dir4", ",") For $i = 1 To $Array[0] Local $DelDir = DirRemove($Array[$i], 1) If $DelDir = 1 Then _FileWriteLog(@HomeDrive & "\Delete.log", " Directory " & $Array[$i] & " was removed") EndIf Next Am I way off? Thanks for the help!! -Mike Edited April 7, 2011 by mdwerne Link to comment Share on other sites More sharing options...
smartee Posted April 7, 2011 Share Posted April 7, 2011 Your original post is using arrays oh and your syntax again$Array = StringSplit(@HomeDrive & "\Dir1,"& @HomeDrive & "\Dir2,"& @HomeDrive & "\Dir3,"& @HomeDrive & "\Dir4", ",") Link to comment Share on other sites More sharing options...
guinness Posted April 7, 2011 Share Posted April 7, 2011 (edited) With response to how to code an Array, with 100 elements this is how you would start it... $aArray[101] = [100, @HomeDrive & "\Dir1", @HomeDrive & "\Dir2", ... An Example with 20 Rows (elements) #include <Array.au3> Global $aArray[21] = [20, "1", "2", "3", "4", "5", "6", "7", "8", _ "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"] _ArrayDisplay($aArray) For $i = 1 To $aArray[0] ConsoleWrite($aArray[$i] & @CRLF) Next Edited April 7, 2011 by guinness UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mdwerne Posted April 7, 2011 Author Share Posted April 7, 2011 Thank you both for the examples...yes, I misunderstood and misspoke. I believe I'm starting to see the light now. -Mike Link to comment Share on other sites More sharing options...
ripdad Posted April 8, 2011 Share Posted April 8, 2011 A hundred folders? This might work out better .. or something like it: #include <array.au3> Local $folders = EnumRootFolders(@HomeDrive) _ArrayDisplay($folders) $folders[1] = 'C:\MyKeyName-0001-2011'; Example with KeyName or Pointer (remove when ready) For $i = 1 To $folders[0] If Not StringInStr($folders[$i], 'MyKeyName-') Then ContinueLoop MsgBox(0, 'Delete This Folder?', $folders[$i]) Next Func EnumRootFolders($sPath) Local $string, $sFolder If StringRight($sPath, 1) <> '\' Then $sPath &= '\' Local $hF = FileFindFirstFile($sPath & '*') If $hF = -1 Then Return SetError(-1) While 1 $sFolder = FileFindNextFile($hF) If @error Then ExitLoop If Not @extended Then ContinueLoop $string &= $sPath & $sFolder & '|' WEnd FileClose($hF) Return StringSplit(StringTrimRight($string, 1), '|') EndFunc "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
mdwerne Posted April 8, 2011 Author Share Posted April 8, 2011 A hundred folders? This might work out better .. or something like it: #include <array.au3> Local $folders = EnumRootFolders(@HomeDrive) _ArrayDisplay($folders) $folders[1] = 'C:\MyKeyName-0001-2011'; Example with KeyName or Pointer (remove when ready) For $i = 1 To $folders[0] If Not StringInStr($folders[$i], 'MyKeyName-') Then ContinueLoop MsgBox(0, 'Delete This Folder?', $folders[$i]) Next Func EnumRootFolders($sPath) Local $string, $sFolder If StringRight($sPath, 1) <> '\' Then $sPath &= '\' Local $hF = FileFindFirstFile($sPath & '*') If $hF = -1 Then Return SetError(-1) While 1 $sFolder = FileFindNextFile($hF) If @error Then ExitLoop If Not @extended Then ContinueLoop $string &= $sPath & $sFolder & '|' WEnd FileClose($hF) Return StringSplit(StringTrimRight($string, 1), '|') EndFunc Thanks for the alternate method ripdad, I appreciate your input! Link to comment Share on other sites More sharing options...
ripdad Posted April 8, 2011 Share Posted April 8, 2011 You're welcome. Another suggestion ... It's generally not a good idea to work off the root of your harddrive, especially with 100 folders. Windows won't let you delete C:\Windows - but other files/folders would be at risk. Many accidents can be avoided if you move your project/folders to a subfolder. Example: C:\MyWorkFolder "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward 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