Sign in to follow this  
Followers 0
romulous

Help with Looping while Array not Empty

6 posts in this topic

Hi everyone,

I have the following code:

#include <File.au3>; Include "File Management" User Defined Functions (UDF)
#Include <Array.au3>; Include "Array Management" User Defined Functions (UDF)

AutoItSetOption ( "TrayIconHide", 1 ); Hides AutoIt tray icon

; Start of Explicit Variables Listing
$Array_Inc = 0
$FileList = _FileListToArray ( "C:\Downloads", "*.tif", 1 ); Variable used to hold the array of TIFF files found, the $iFlag=1 parameter restricts the search to files only (no folders)

If @Error = 1 Then; If no TIFF files were found
    MsgBox ( 0, "Error" , "No TIFF Files Found." ); Display MsgBox with error message
    Exit; Exits
EndIf

While 1
FileCopy ( $FileList[1+$Array_Inc], "C:\TempFiles" )
$Array_Inc = $Array_Inc + 1
WEnd

_ArrayDisplay ( $FileList, "$FileList" ); Displays the array containing the found TIFF files

The code is the first part of a script i am writing to use a command line tool on multiple TIFF images (I use the FileCopy function just to test with until I can get the code working). The problem is, I don't know how many TIFF files will be in the folder, and what they will be named (thus the use of the Array). The Array seems to work fine, the problem I am having is running that FileCopy loop while the Array is not empty (in other words, if I have 10 TIFF files in the folder - and thus in the Array - I want the FileCopy to operate on every single one of them until it reaches the end of the Array, where it continues on with the ArrayDisplay line). The error I am receiving at the moment is:

FileCopy ( $FileList[1+$Array_Inc], "C:\TempFiles" )

FileCopy ( ^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

I think I know why the error is occurring (the constant "+1" is incrementing the Array index past the total number of files in the Array), but no idea as to how to actually achieve what I want. Any help would be appreciated (and I expect that as I continue to code, I may have many more questions!).

Thanks,

CM

Share this post


Link to post
Share on other sites



#include <File.au3>; Include "File Management" User Defined Functions (UDF)
#Include <Array.au3>; Include "Array Management" User Defined Functions (UDF)

AutoItSetOption ( "TrayIconHide", 1 ); Hides AutoIt tray icon

; Start of Explicit Variables Listing
$Array_Inc = 0
$FileList = _FileListToArray ( "C:\Downloads", "*.tif", 1 ); Variable used to hold the array of TIFF files found, the $iFlag=1 parameter restricts the search to files only (no folders)

If @Error = 1 Then; If no TIFF files were found
    MsgBox ( 0, "Error" , "No TIFF Files Found." ); Display MsgBox with error message
    Exit; Exits
EndIf

for $i=0 to Ubound($FileList)-1
FileCopy ( $FileList[$i], "C:\TempFiles" )
next

_ArrayDisplay ( $FileList, "$FileList" ); Displays the array containing the found TIFF files


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <File.au3>; Include "File Management" User Defined Functions (UDF)
#Include <Array.au3>; Include "Array Management" User Defined Functions (UDF)

AutoItSetOption ( "TrayIconHide", 1 ); Hides AutoIt tray icon

; Start of Explicit Variables Listing
$Array_Inc = 0
$FileList = _FileListToArray ( "C:\Downloads", "*.tif", 1 ); Variable used to hold the array of TIFF files found, the $iFlag=1 parameter restricts the search to files only (no folders)

If @Error = 1 Then; If no TIFF files were found
    MsgBox ( 0, "Error" , "No TIFF Files Found." ); Display MsgBox with error message
    Exit; Exits
EndIf

for $i=0 to Ubound($FileList)-1
FileCopy ( $FileList[$i], "C:\TempFiles" )
next

_ArrayDisplay ( $FileList, "$FileList" ); Displays the array containing the found TIFF files
Hi,

Thanks, that seems to work nicely - the error has disappeared, and the TIFF files copy to the right folder. I think I need to replace the FileCopy with the command line tool now (exiftool) that this part seems to work. Once I do that, I need to put a function in before that code to try and work out how many pages each TIFF file has (each TIFF is a multi-page TIFF, which is an additional complication, because I need exiftool to work on every page in each TIFF file). And I also need to work out how to pass command line switches to a program via AutoIt - exiftool needs some switches to work, and the AutoIt Run command does not seem to have a parameter for switches...

Regards,

CM

Edited by romulous

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

And I also need to work out how to pass command line switches to a program via AutoIt - exiftool needs some switches to work, and the AutoIt Run command does not seem to have a parameter for switches...

The Run() function takes the entire command line, including any switches, as a single string:
$sSource = "C:\Temp\Test\*.*"
$sDest = "E:\Backups\Test\"
$sCmdString = "xcopy " & $sSource & " " & $sDest & " /d/e/v/c/y"
Run($sCmdString, @TempDir, @SW_MINIMIZE)

The ShellExecute() function takes the executable path as one string and the parameters as another:

$sSource = "C:\Temp\Test.txt"
ShellExecute("Notepad.exe", $sSource, @TempDir, "Open")

More time with the help file, including the tutorials and example scripts found there, would be a good thing.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The Run() function takes the entire command line, including any switches, as a single string:

$sSource = "C:\Temp\Test\*.*"
$sDest = "E:\Backups\Test\"
$sCmdString = "xcopy " & $sSource & " " & $sDest & " /d/e/v/c/y"
Run($sCmdString, @TempDir, @SW_MINIMIZE)

The ShellExecute() function takes the executable path as one string and the parameters as another:

$sSource = "C:\Temp\Test.txt"
ShellExecute("Notepad.exe", $sSource, @TempDir, "Open")

More time with the help file, including the tutorials and example scripts found there, would be a good thing.

:)

Thanks PsaltyDS. I tend to rely on the helpfile a lot, when it opens that is. I don't know if anyone else has ever had this problem or not, but it goes back a number of versions for me - when I go Help-Help in SciTE, the AutoIt helpfile refuses to open about 95% of the time...

CM

Share this post


Link to post
Share on other sites

Thanks PsaltyDS. I tend to rely on the helpfile a lot, when it opens that is. I don't know if anyone else has ever had this problem or not, but it goes back a number of versions for me - when I go Help-Help in SciTE, the AutoIt helpfile refuses to open about 95% of the time...

CM

I've never had that problem, but I run the help file from a script anyway. The script checks for the existence of Production and Beta help files, and opens which ever one is most recent. I keep the help file open and at least minimized on the task bar the entire time I am scripting.

It's a nice basic script that is genuinely useful. You should make yourself one.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0