xcaliber13 Posted October 25, 2018 Share Posted October 25, 2018 Can someone point out what I am doing wrong? I have a directory that I want to move half the files to another directory. My script does not stop when the counter is at zero $hFileList = _FileListToArray("C:\PPATemp\SecondPage","*", $FLTA_FILES) $iCount = UBound($hFileList, $UBOUND_ROWS) -1 $fCount = $iCount /2 Do For $i = 1 To UBound($hFileList) -1 FileMove("C:\PPATemp\SecondPage\"& $hFileList[$i], "C:\PPATemp\SecondPage\Temp\"& $hFileList[$i]) $fCount = $fCount -1 Next Until $fCount = 0 Just ends up moving all of the files. And never exit the loop. Thank you Link to comment Share on other sites More sharing options...
Developers Jos Posted October 25, 2018 Developers Share Posted October 25, 2018 (edited) Quick lesson on debugging: Add consolewrites in the code to show what it is doing ... something like: #include <AutoItConstants.au3> Global $hFileList[11] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] $iCount = UBound($hFileList, $UBOUND_ROWS) - 1 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iCount = ' & $iCount & @CRLF) ;### Debug Console $fCount = $iCount / 2 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fCount = ' & $fCount & @CRLF) ;### Debug Console Do For $i = 1 To UBound($hFileList) - 1 FileMove("C:\PPATemp\SecondPage\" & $hFileList[$i], "C:\PPATemp\SecondPage\Temp\" & $hFileList[$i]) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hFileList[$i] = ' & $hFileList[$i] & @CRLF) ;### Debug Console $fCount = $fCount - 1 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fCount = ' & $fCount & @CRLF) ;### Debug Console Next ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fCount = ' & $fCount & @CRLF) ;### Debug Console Until $fCount = 0 You will quickly see what you have done wrong. Jos Spoiler possible solution #include <AutoItConstants.au3> Global $hFileList[11] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] $iCount = UBound($hFileList, $UBOUND_ROWS) - 1 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iCount = ' & $iCount & @CRLF) ;### Debug Console $fCount = $iCount / 2 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fCount = ' & $fCount & @CRLF) ;### Debug Console For $i = 1 To UBound($hFileList) - 1 FileMove("C:\PPATemp\SecondPage\" & $hFileList[$i], "C:\PPATemp\SecondPage\Temp\" & $hFileList[$i]) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hFileList[$i] = ' & $hFileList[$i] & @CRLF) ;### Debug Console $fCount = $fCount - 1 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fCount = ' & $fCount & @CRLF) ;### Debug Console if $fCount = 0 then exitloop Next Edited October 25, 2018 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...
gruntydatsun Posted October 26, 2018 Share Posted October 26, 2018 Depending on how big $hFileList is your inner loop could result in $fCount becoming a negative number while inside your inner loop, so the "Until $fCount=0" condition of your outer loop may never be satisfied. If $fCount is being calculated the way you need it to be you could change the last line to: Until $fCount <= 0 Link to comment Share on other sites More sharing options...
spudw2k Posted October 26, 2018 Share Posted October 26, 2018 The reason it moves everything is because the for > next loop doesn't know to exit when the desired $fCount value is reached. @gruntydatsun Has a paint about the $fCount value going into the negative, but the real problem is the for loop. One way you could address this is eliminate the Do loop, and put a check in the for loop to evaluate the value of $fCount and then ExitLoop. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
xcaliber13 Posted October 29, 2018 Author Share Posted October 29, 2018 Ok back from a long weekend, Thank you for all the help. spudw3k your advice did the trick. Again thank you to all for your help. 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