Rykk Posted September 27, 2010 Share Posted September 27, 2010 Hi all. First off, note that I barely know what I'm doing so references to C++ coding or other scripting languages and processes just might go right over my head....Anyhow, I wrote an AutoIT script that copies a folder(with subfolders) from the C: drive to a USB memory stick that made a txt file with start/stop times, total seconds for the folder copy, a progress bar showing also MB copied, folders copied, and files copied as the process went along. The script writes the data to the stick and then deletes it 5 times and then calculates the average seconds for the 5 iterations of the loop. We're evaluating throughput on a number of memory sticks where I work. Integral to this was the "DirGetSize" command with the optional flag set to "1". This flag is supposed to make the DGS command return total size, number of folders, and number of files as a "one dimensional array". Worked great.So far, so good. Next, I tried to make a script that moves(not copies) a test folder from C: to the memory stick and then reads it from the stick and copies it down to C: with the same bells and whistles as the above has, just copying from the stick rather than to it. I have run into a problem that confuses the heck out of me with a bit of code that worked in the first script but not the second. I'm using a debugger "AutoIT Debugger ver 0.32.0.0 made by Steve Towner. It tells me that there is a "subscript used on a non-array variable". Problem is that I DID set it as an array when I said: "$ss = DirGetSize("C:\the folder", 1) where the "1" flag is supposed to make it return an array with the total size in Mb, no. of folders, and no. of files. The problem line comes next where I say: "$percent = $ss[0] / 1.Why does this not work? It works in the original script - although this debugger says it has the same problem, as well, but the thing works fine when you run it on our test PC and mem stix.Here's the code snippet where the problem is - it is the very beginning of the script: #include <file.au3> _FileCreate(@DesktopDir & "\Read Times.txt")For $i = 1 to 5 Step 1 $ss = DirGetSize("C:\4G", 1) $percent = $ss[0] / 100 Run(@DesktopDir & "\MDLLMoveDir.exe") ProgressOn("MDL Lite Read Test", "Folder Move Progress ", $percent & "%", 312, 234, 16) Do $ds = DirGetSize("D:\4G", 1) ProgressSet(Round($ds[0] / $1_percent, 2), Round($ds[0] / (1024 * 1024), 2) & " MB of " & Round($ss[0] / (1024 * 1024), 2) & " MB moved" & @CRLF _ & $ds[1] & " of " & $ss[1] & " Files moved." & @CRLF _ & $ds[2] & " of " & $ss[2] & " Folders moved", "Write Status - " & Round($ds[0] / $percent, 1) & "%") Until Number($ds[0] >= $ss[0]) ProgressSet(100, "Done", "Test Folder Installed") Sleep(2000) ProgressOff() Sleep(1000)This exact code, except for changes to title and text in the windows worked fine in the original script, which a snippet of follows: #include <file.au3> _FileCreate(@DesktopDir & "\Write Time.txt")For $i = 1 to 5 Step 1 If $i <= 5 Then DirCreate("D:\4G") $ss = DirGetSize("C:\4G", 1) $percent = $ss[0] / 100 _FileWriteLog(@DesktopDir & "\Write Time.txt", " - Started") $start = TimerInit() Run(@DesktopDir & "\MDLLCopyDir.exe") ProgressOn("MDL Lite Write Test", "Write Progress", $percent & "%", 312, 234, 16) Do $ds = DirGetSize("D:\4G", 1) ProgressSet(Round($ds[0] / $percent, 2), Round($ds[0] / (1024 * 1024), 2) & " MB of " & Round($ss[0] / (1024 * 1024), 2) & " MB copied" & @CRLF _ & $ds[1] & " of " & $ss[1] & " Files copied." & @CRLF _ & $ds[2] & " of " & $ss[2] & " Folders copied.", "Write Status - " & Round($ds[0] / $percent, 1) & "%") Until Number($ds[0] >= $ss[0]) $diff = TimerDiff($start) _FileWriteLog(@DesktopDir & "\Write Time.txt", " - Ended") $x = Number($diff / 1000) $y = Round($x) ProgressSet(100, "Done", "Write Complete") ProgressOff() FileWriteLine(@DesktopDir & "\Write Time.txt", $y) Sleep(2000) SplashTextOn ("MDL Lite Write Test", "Removing Files...", 250, 125, 312, 156, 2, "", 24, 600) DirRemove("D:\4G", 1) SplashOff() Sleep(1000)EndIfNextWhy does it work in the second one and not the first?Thanks,Rick Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 27, 2010 Moderators Share Posted September 27, 2010 Rykk,Welcome to the AutoIt forum. At a quick glance the first code snippet will fail as you describe because the folder you are trying to size does not exist. In the second code snippet, you have the lines:DirCreate("D:\4G")$ss = DirGetSize("C:\4G", 1)where I assume D:\4G is the folder you are filling for the tests.The DirCreate line is not in the first snippet. My guess is that the folder does not therefore exist and as a result DirGetSize will fail - just as the Help file tells us it will.Try adding that extra line to your code and see if it makes the difference. M23P.S. When you post code please use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). It makes it much easier to read. 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...
Rykk Posted September 27, 2010 Author Share Posted September 27, 2010 (edited) Thanks - But - The folder, "C:\4G", already exists on the on the C drive of the PC. What I'm - trying - to do is "cut" that folder from C: and "paste" it to the D drive, which is the memory stick and have a progress bar while that is happening so that the user knows it's doing something....and because it's fun! There is a separate autoIT executable on the desktop that gets called by the "Run...MDLLMoveDir" command that handles this. (The only way I could figure to get the progress bar to run WHILE the data was being moved). The problem goes away if I put this within an "If/Then" loop (If $i <= 1 Then...) which is within a "For" (For $i = 1 To 5 Step 1) loop. Similar to how the second snippet is. I don't understand why because the documentation states that the DGS function returns an array and it works except not when outside of any loop. I want this part of the script to only run on the first loop since the memory sticks will need to have the test folder put on them before we can then read/copy that folder from the stick back down to the hard drive, note the time elapsed, and then delete it and copy/read again a total of 5 times. Thanks - I'll keep plugging (more like pecking - lol) away and will remember to format the code correctly if I post more snippets. C-ya, Rick Edited September 27, 2010 by Rykk Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2010 Moderators Share Posted September 28, 2010 Rykk,Sorry about last night's reply - I can only offer the excuse I was very tired. I cannot reproduce your symptoms - but then I am not using your MDLLCopyDir.exe. Could this possibly lock the folder and prevent access by DirGetSize? Nothing else seems to fit the bill - although it does not explain why it does work with the added If...Then structure. A question. You are copying the same folder over and over again - so why do you need to read its size each time you loop? Why not put that part of the code OUTSIDE the For...Next loop - the values are not going to change between runs are they? Something like this:#include <file.au3> _FileCreate(@ScriptDir & "\Write Time.txt") ; Do it just the once here $ss = DirGetSize("C:\4G", 1) $percent = $ss[0] / 100 For $i = 1 To 5 _FileWriteLog(@ScriptDir & "\Write Time.txt", " - Started") $start = TimerInit() Run(@ScriptDir & "\MDLLCopyDir.exe") ProgressOn("MDL Lite Write Test", "Write Progress", $percent & "%", 312, 234, 16) Do $ds = DirGetSize("D:\4G", 1) ProgressSet(Round($ds[0] / $percent, 2), Round($ds[0] / (1024 * 1024), 2) & " MB of " & Round($ss[0] / (1024 * 1024), 2) & " MB copied" & @CRLF _ & $ds[1] & " of " & $ss[1] & " Files copied." & @CRLF _ & $ds[2] & " of " & $ss[2] & " Folders copied.", "Write Status - " & Round($ds[0] / $percent, 1) & "%") Until $ds[0] >= $ss[0] $diff = TimerDiff($start) _FileWriteLog(@ScriptDir & "\Write Time.txt", " - Ended") $x = Number($diff / 1000) $y = Round($x) ProgressSet(100, "Done", "Write Complete") Sleep(2000) ProgressOff() FileWriteLine(@ScriptDir & "\Write Time.txt", $y) SplashTextOn("MDL Lite Write Test", "Removing Files...", 250, 125, 312, 156, 2, "", 24, 600) DirRemove("D:\4G", 1) Sleep(1000) SplashOff() NextThat way you should get around your problem - even if it remains unsolved. I hope this is of more help. 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...
Rykk Posted September 28, 2010 Author Share Posted September 28, 2010 Thanks! It DOES make sense to just get the size once and be done with it. As to the problem of the script claiming that $ss[0] is a "non-array variable", I'm still stumped. When I step thru the script with the AutuIT Debugger, it freaks on line 5 and points to the [0] in the statement. Here's the line, along with the previous one that expressly says (the flag set to "1") to return a "one dimensional array" per the help files: Line4 -- $ss = DirGetSize("C:\4G", 1) Line5 -- $percent = $ss[0] / 100 That said, as to the external program - MDLLDirMove.exe. The debugger calls the problem out where I just said but, when you actually run the script, it DOES get to at least the point of launching MDLLmove before - or right as - the main script quits with the non-array variable error. The PC's we are using this on are military equipment. Very robust but, also, VERY slow. The script that works has a couple of things to do b4 it tells MDLLxx to run. I wonder if maybe it happens too fast for either the PC or AutoIT? I'm going to take a shot in the dark and insert a 1 or 2 second sleep pause between defining the formula to calculate percent and running the external script....I'll let ya know... C-ya, Rick 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