Count files in folder based on criteria and select in order?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Bob's code works for me.

Post by gdyvig » Fri Jun 19, 2009 4:01 pm

Hi RNIB,

I tried out Bob's code and it worked for me.

Make sure you do not have any spaces before or after the commas in the commands. The leading or trailing spaces become part of the varialble names. Also be sure to Edit>Remove trailing spaces before saving your script.

You can also check the watchlist to see what veriables get created. The easiest way is to do a Debug>Trace.

Gale

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Jun 19, 2009 6:57 pm

For RNIB:
Did you modify the first line to use the directory where your *.wav files are located?

For JRL:
You MUST get familiar with RegEx. FYI, the expression I used in my example also provides a list of all the files that begin with a number. They each are in a sequentially numbered variable %vFiles_n%. If in Debug mode, you will see the variables and their values in the WatchList. Or, you can loop this array to display/write/rename, etc.

You can change the needles to locate files in the haystack that do not begin with numbers and use essentially the same RegEx to locate those files.

Here is an untested example........

Code: Select all

GetFileList>c:\windows\*.wav,vFileList,;
Let>vNeedle1=[0-9]+[a-z]+.*?\.wav
Let>vNeedle2=;[a-z]+.*?\.wav
Let>vHaystack=%vFileList%
RegEx>%vNeedle1%,%vHaystack%,0,vNumberFiles,vNFileCount,0,,
RegEx>%vNeedle2%,%vHaystack%,0,vAlphaFiles,vAFileCount,0,,
MessageModal> There are %vNFileCount% filenames that start with a number
MessageModal> There are %vAFileCount% filenames that start with a letter
// Insert loops here to process each of the file names........
--------------------------------------------
For ALL:

And here is an online RegEx testing tool, roll over the expressions to see what they do, see results as you type, many nice features....
http://www.gskinner.com/RegExr/
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Post by RNIB » Wed Jun 24, 2009 11:04 am

Bob Hansen wrote:For RNIB:
Did you modify the first line to use the directory where your *.wav files are located?
Sorry Bob, I've been off sick for a few days and only just got back.

I've tried it again, and yes I've changed the path to the one containing my WAV files:

Code: Select all

GetFileList>F:\Beyond Ugly\*.wav,vFileList,;
Let>vNeedle=[0-9]+[a-z]+.*?\.wav
Let>vHaystack=%vFileList%
RegEx>%vNeedle%,%vHaystack%,0,vFiles,vFileCount,0,,
MessageModal>There are %vFileCount% filenames that start with a number

I've checked that there aren't any spaces before or after any commas or any trailing spaces but still I just get a message box that just says "There are %vFileCount% filenames that start with a number".

I wonder if this might be down to the fact that I'm only running MacroScheduler 10? Unfortunately as a charity and in the current financial climate we can't really afford to upgrade to version 11 at the moment :cry:

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Wed Jun 24, 2009 2:49 pm

Hi RNIB,

You were able to purchase the 2 year Upgrade Protection Plan with the original software.

If so, you still have 6 months of free upgrades.

If not, you may be to work something out based on this quote in the "Buy Now" page:
Want to barter, trade, beg or borrow?
It is also possible to run RegEx via VBScript. Or you can use the alternate solution provided by JRL.


I tried running your code again today. This time the GetFileList is not returning a value. Use the Watch List to make sure all your input variables have values before going into RegEx.

I'm going to see what is wrong with GetFileList now.


Gale

RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Post by RNIB » Wed Jun 24, 2009 3:12 pm

Sorry meant to say earlier that I had tried JRL's script but unfortunately this doesnt seem to work correctly. No matter what folder I point it at it just gives me a count of the total number of WAV files in there.
E.g. if a folder contains 200 WAV files and 190 of them are prefixed with a number I just get a message saying:

Numbered=0
NotNumbered=200

I've learnt a lot over the past week or so in trying to do this and can actually understand 90% of JRL's code but can't figure out where it's going wrong.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

file includes directory

Post by gdyvig » Wed Jun 24, 2009 3:51 pm

Hi RNIB,

The problem is %file% also includes the directory name.

Add this code after you have captured %dir%

Length>%dir%\X,startdigit.
(The X is just a placeholder for first character of filename)

Then change your Midstr command to:

MidStr>%file%,%startdigit%,1,digit


Gale

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Jun 24, 2009 10:11 pm

Yes, my code will not work with Version 10.

RegEx was introduced with Version 11.1.05 on Mar 02 2009.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts