Alexis Posted April 21, 2009 Report Share Posted April 21, 2009 Is there any possibilty to count the number of files which are located in one specific folder and make an integer variable of it? Thank you very much! Quote Link to comment Share on other sites More sharing options...
redcordial Posted April 21, 2009 Report Share Posted April 21, 2009 Hi Alexis, try this: Edited: The variable FileCount is first set to zero. Replace "C:\\TestFolder" with the path to your own folder. Cheers <VARIABLE SET INTEGER Option="\x00" Destination="%FileCount%" Value="0"/> <REPEAT WITH FOLDER Path="C:\\TestFolder" OnlyFiles="TRUE" Destination="%MyStr%" FullPath="FALSE" ProcSubfolders="FALSE"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%FileCount%"/> <END REPEAT/> Quote Link to comment Share on other sites More sharing options...
Cory Posted April 21, 2009 Report Share Posted April 21, 2009 Just what I was going to suggest but I would add that you don't need to initially set the counter to zero. It's default value is zero even if it doesn't show up that way in the debugger. Alexis you may want to add some conditions. Modern windows OS's often contain hidden and system files like thumbs.db that you do not want to count. There are a hundred ways to skin a cat but I find using a combination of "If File Attribute" Hidden and System usually does the trick. <IF FILE ATTRIBUTE Filename="c:\\test.txt" Attribute="Hidden"/> <AND/> <IF FILE ATTRIBUTE Filename="c:\\test.txt" Attribute="System"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%FileCount%"/> <END IF/> Of course you can add conditions forcertian extensions and all kinds of stuff. Quote Link to comment Share on other sites More sharing options...
Alexis Posted April 22, 2009 Author Report Share Posted April 22, 2009 Got it! Thank you Quote Link to comment Share on other sites More sharing options...
Rustywinger Posted April 22, 2009 Report Share Posted April 22, 2009 Cory: The main case for resetting an integer to zero is that script above may be inserted into a Macro file that saves and restores Variables... but I know you knew that! Just some experience I learned after I needed it the most! Quote Link to comment Share on other sites More sharing options...
Cory Posted April 22, 2009 Report Share Posted April 22, 2009 So if you know I knew that why mention it? JK. I'm not saying that you can't do it, I just think that in many cases people don't realize you don't need to except in cases like you described. In this case there was no loop. There are several things like that, in fact just the other day I helped a user realize they don't need to include a Macro Return at the end of all their sub-macros. Quote Link to comment Share on other sites More sharing options...
redwards Posted April 22, 2009 Report Share Posted April 22, 2009 Just what I was going to suggest but I would add that you don't need to initially set the counter to zero. It's default value is zero even if it doesn't show up that way in the debugger. Alexis you may want to add some conditions. Modern windows OS's often contain hidden and system files like thumbs.db that you do not want to count. There are a hundred ways to skin a cat but I find using a combination of "If File Attribute" Hidden and System usually does the trick. <IF FILE ATTRIBUTE Filename="c:\\test.txt" Attribute="Hidden"/> <AND/> <IF FILE ATTRIBUTE Filename="c:\\test.txt" Attribute="System"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%FileCount%"/> <END IF/> Of course you can add conditions forcertian extensions and all kinds of stuff. I pasted the above code into the latest version of MCP. Clicked the [save] button in the editor and it spit back this: Line 5: Mismatched 'End If' Quote Link to comment Share on other sites More sharing options...
Cory Posted April 23, 2009 Report Share Posted April 23, 2009 Yeah, I see the same thing. Simply having a single If File Attribute followed with an End If causes it as well so it's not the AND. I'll report it as a bug. Whatever you do don't try to run that script, it will crash MEP! BTW, I made a mistake, there should be Else in there so we count the visible non-system files. That is of course if the AND was working. Quote Link to comment Share on other sites More sharing options...
yaqwa Posted June 2, 2011 Report Share Posted June 2, 2011 Wonderful - i searched for this for a while. But what i need is a little bit more. Maybe you can help me for this. Ok i created a FileCOunt. this works fine but now comes the difficult problem. I want to show it but not in a Text box. There are several possibilities but i do not know what works and what not. So Possibility 1 (like most) can place a icon in the taskbar wo tells me how many files are in the folder but i think this can not work (i had a program named samurize there it worked but samurize will not run under Win 7 64 bit in the taskbar) 2. this could maybe work and will be ok for me changed an icon in the taskbar depending of how many files are in the folder ( means if there are 50 files the icon changed to lets say 50.ico and if there are 1000 it will change to 1000.ico or similiar.) if this will not work in the taskbar maybe it can work on the desktop? help would be great Quote Link to comment Share on other sites More sharing options...
Cory Posted June 2, 2011 Report Share Posted June 2, 2011 You should really have started this as a new thread. You could always make it the title of a text box you leave open. You could create your own Windows Gadget. Quote Link to comment Share on other sites More sharing options...
yaqwa Posted June 2, 2011 Report Share Posted June 2, 2011 thanks i created a new thread Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.