Grantson Posted November 7, 2014 Share Posted November 7, 2014 HI Guys Once again, I think (I hope) i just need some fresh eyes to tell me what im missing here I wrote a script to step through the user profiles on a remote PC and clear out the temp files (that bit seems to work) I wanted to ad a bit at the end to clear the windows temp folder on the remote PC at the same time so i added this chunk form the already working code for the individual user temp files Local $FileList = _FileListToArray($windowsTemp,"*") If @error = 1 Then MsgBox(0, "", "No Folders Found.") EndIf If @error = 4 Then MsgBox(0, "1", "No Files Found.") EndIf _ArrayDisplay($FileList) For $element In $FileList $isDir = FileGetAttrib($windowsTemp&"\"&$FileList[$element]) If StringInStr($isDir, "D") Then $size = DirGetSize($windowsTemp&"\"&$FileList[$element]) if $size = 0 then DirRemove($temppath&"\"&$FileList[$element]) Else FileDelete($windowsTemp&"\"&$FileList[$element]) MsgBox(0,"",$windowsTemp&"\"&$FileList[$element]) ;diagnostic EndIf Next The file list populates with the directory listing as expected and the array display lists the entire directory listing as expected The diagnostic message box will give the correct path and then gets stuck on element 0 It then gets stuck in an infinite loop bringing up a message box with targetpcc$windowstemp486 486 being the number of files in the temp folder I'm sure I'm missing something silly that's making it stick but I'm now at the point I cant see it for staring at it Thanks Grant Link to comment Share on other sites More sharing options...
Solution Danp2 Posted November 7, 2014 Solution Share Posted November 7, 2014 I believe all references to $FileList[$element] are incorrect and should only be $element. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 7, 2014 Moderators Share Posted November 7, 2014 Element 0 of _FileListToArray is the number of files found. As stated by Danp2, your use of For/In is incorrect. Instead of this: For $element In $FileList Try this: For $element = 1 To Ubound($FileList) - 1 Grantson 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Grantson Posted November 7, 2014 Author Share Posted November 7, 2014 Thanks Danp2 That's got it Sm0ke_N Ill have a look at ubound also. Looping and arrays is always something that seems to break my brain 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