Loop for each - Forum

Forum Navigation
You need to log in to create posts and topics.

Loop for each

Hi is anyone able to point me in the right direction please?

I am looking to loop through a list of files and perform and action on the list of files.

I cannot see how to perform a "loop for each" as that action does not exist.

TIA

Mark

@mark-waples

I am looking to loop through a list of files and perform and action on the list of files.
I cannot see how to perform a "loop for each" as that action does not exist.

You did not elaborate on the form/format of the list of files ... so I am going to assume that you used something like ...

FileList "C:\My Photos\*.jpg" "Files" "[Pics]"

... now, [Pics] will contain the names (separated by carriage returns i.e. [#13]) ... so you do something like ...

StrParse "[Pics]" "[#13]" "[Names]" "[Count]"

... to get the file names in variables [Names1], [Names2], ... [Names143] etc. ... [count] tells you how many such variables were created.

Finally, you process each entry using the Loop/EndLoop code block ...

Loop "1" "[count]" "[thisEntry]"
   SetVar "[thisFileName] "[Names[thisEntry]]"
   ... enter you script actions for this File Name here e.g.
   AlertBox "File Name" "File [thisEntry] of [count] is called [thisFilename]"
EndLoop

 

luishp and Vadim have reacted to this post.
luishpVadim

@gaev

Many thanks - I ended up with this and it works perfectly.

 

FolderBox "Select a Folder:" "[FOLDERS]"
FileList "[FOLDERS]\*.*" "Files" "[FILELIST]"
StrParse "[FILELIST]" "[#13]" "[Names]" "[Count]"

Loop "1" "[count]" "[thisEntry]"
   SetVar "[thisFileName]" "[Names[thisEntry]]"

... enter you script actions for this File Name here e.g.
dbpImportFromCSV "main" "Table1" "[PubDir]\SplitFiles\[thisFileName]" "Delimiter=,;ContainsFieldNames=No;MatchFieldNames=No"

Balloon "IMPORTING...|PLEASE BE PATIENT!||IMPORTING FILE:||File [thisEntry] of [count] - [thisFilename]" "-1" "-1" "2000"
  
EndLoop

Thanks again - very helpful! :)