Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Loop, Files and Folders


  • Please log in to reply
5 replies to this topic
sosaited
  • Members
  • 278 posts
  • Last active: Oct 06 2009 06:08 PM
  • Joined: 24 Feb 2005
It would be useful if File and Folder Loop would accpet MULTIPLE PATTERNS :

Loop, "C:\My Docs\*.jpg" "C:\My pics\*.jpg" "D:\New\*.ahk",1, 1
{
---------
}

My small "thanks" to AHK in shape of these dedicated 3d images
Posted Image

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005
Maybe the following construct will suffice until this wish is granted:

pattern = c:\program files\*.ahk|*.jpg
loop, Parse, pattern, |
	loop, %A_LoopField%, 1, 1
		found = %found%`n%A_LoopFileFullPath%

MsgBox, %found%


sosaited
  • Members
  • 278 posts
  • Last active: Oct 06 2009 06:08 PM
  • Joined: 24 Feb 2005
I think you meant something like this :?:

pattern = C:\docs\*.jpg|C:\docs\*.ahk
Loop, Parse, pattern, |
{
  Loop, %A_LoopField%,1, 1
  {
    ......
  }
}


by the way, this method takes very long (compared to the Wish i posted) if the "Operations" in the both Loops are same. i.e if only one Loop is running (working on BOTH jpg, ahk) each command in it will act on both type of files, thus saving time

Thanks
My small "thanks" to AHK in shape of these dedicated 3d images
Posted Image

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

I think you meant something like this :?:


No. What I posted is correct. You would of course need to adjust the details to suit your needs.


by the way, this method takes very long (compared to the Wish i posted) if the "Operations" in the both Loops are same. i.e if only one Loop is running (working on BOTH jpg, ahk) each command in it will act on both type of files, thus saving time


How is that? For each iteration of the loop, only one file will be acted upon. The result will be the same for the one loop or two loop method. Also, there is only one active loop in the two loop method. The outer loop acts as a server for the inner loop, where various operations (i.e., activities) will occur.

Any significant performance differential can be accounted for in the outer parsing loop, which should be minimal.

In any case, the suggested construct is designed to be a temporary [purely AHk] solution. Although, the non-script solution will be similar.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I don't see the difference between the 2 scripts above, except the braces, which some prefer to add (who is paid by the number of lines of code he writes). But there can be a factor of 2 slow down with the double loop method. If the directory is huge, and only a few entries are processed, scanning the files consumes most of the running time. And if you have many patterns, like *.jpg, *.jpeg, *.gif, *.tif, *.tiff ... this slowdown can be significant. There are over a hundred different picture file extensions, so finding the pictures can take 100 times longer than necessary.

The other loop order is not better, either, when we find all the files and check if their extensions are in a list. In this case the slow interpreted script has to touch each file, instead of the faster internal search. This wish can really speed up things.

FlintW
  • Members
  • 2 posts
  • Last active: Nov 13 2015 07:22 AM
  • Joined: 28 Oct 2015

You can Loop through your Files with *.*, get the Fileextension, compare it to your Whitelist and then do your command.