[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

directory count for filetype

Posted on 2008-09-29
16
Medium Priority
?
264 Views
Last Modified: 2013-12-24
Hello,
I'm looking for a solution to count the number of files in a directory of a specific filetype.
ex.
I want to know how many jpgs (or any specific filetype) are in the directory (not recursive)

do not post a solution that filters the cfdirectory as I need all files returned
and also don't post a solution that loops through the results and increments a counter when filetype is found

thanks
0
Comment
Question by:dgrafx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
16 Comments
 
LVL 11

Accepted Solution

by:
BrianMM earned 2000 total points
ID: 22596514
Hi,

You can just

<cfdirectory directory="[directory]" name="qryDirectoryList" action="LIST">

You can then use QoQ (Queries of Queries) to query the entire result set of the cfdirectory...

<cfquery type="query">
SELECT *
FROM qryDirectoryList
WHERE Name LIKE '%.jpg'
</cfquery>

Or perhaps the 'type' attribute from this query... do a cfdump on qryDirectoryList to check what deta is returned! :)

HTH :)
0
 
LVL 11

Expert Comment

by:BrianMM
ID: 22596539
P.s. small typo! - obviously in the <cfquery ..> that's DBTYPE="query"
0
 
LVL 25

Author Comment

by:dgrafx
ID: 22596690
I forgot to add the "QofQ" to the don't post list
I'm really sorry ...

Do you have any ideas along the lines of regex?
thanks
0
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
LVL 63

Expert Comment

by:Zvonko
ID: 22597479
Here the RegExp solution:

<cfdirectory directory="#GetDirectoryFromPath(GetTemplatePath())#" name="myList" action="LIST" filter="*.cfm" >
 
<cfoutput>#myList.RecordCount#</cfoutput>

Open in new window

0
 
LVL 25

Author Comment

by:dgrafx
ID: 22597687
I need to count multiple filetypes from ONE query (cfdirectory) so the results cannot be filtered

thanks
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22597855
There is no such thing as cached directory list of all entries where you can filter afterwards for two or three attributes except you do QofQ as already proposed.
Can you specify a bit more details what you are asking?
And why do you want to speed up the queries by complicating scripting? The filter parameter is exactly for that what you are asking for. And the caching is done by operating system. Or do you have three thousand files in one folder???

0
 
LVL 25

Author Comment

by:dgrafx
ID: 22598093
The reason I didn't provide detailed details on what I want to accomplish is that it would take me a bit to explain and was hoping someone else had needed to do something similar and had already spent time writing a function to do this.

I'm going to accept brians post although I'm not sure if I'll use it.
This isn't something I'm actively working on but ran accross code this morning where I had always planned on working out a better way

thanks ...
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22598354
OK, that explains the question.
Hope to be of more help when you need more details for the new approach.

See you.
0
 
LVL 25

Author Comment

by:dgrafx
ID: 22605558
Hi Guys,
Here is the solution that was like I was hoping to find and is what I meant by a regex solution
CF8 to the rescue
I need to start reading the docs more!

<cfset numret=arraylen(REMatch(replace(lcase(fileTypes),",","|","all"), lcase(valuelist(files.name))))>
the cfdirectory query is named files
fileTypes is a list of file types that the current user is allowed to access - i.e. ".jpg,.gif,.png"
numret is the count I was looking for

in a library may be a collection of files of various types
one user may be able to access .jpgs & .gifs and another user may be able to access psd's as well

The whole thing boils down to wanting to display a count of how many files
You know like "73 files in this Library - displaying 1-20"

This rematch gadget is pretty cool - I imagine there will be awesome uses for it much neater than what I'm doing with it here.

I'd like to reopen this question and award this as the answer.
Now this isn't to save points as I have unlimited.
It's just so that someone who may search and finds this question may not read down this low in the post, but just look at the accepted answer.
Before I do that please give your input as to if you mind or not brianmm.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22611809
When you so care about correct solution then you should care also for the correct question wording.
You definitely asked for ONE SPECIFIC FILETYPE. Down the line you explained that is not directly what you want.

So now please open a new question and state both: your corrected question and your answer.

The accepted answer in this question is the correct answer to your initial question.
And the answer does not depend on what you are going to do with the answer. It has only to be the correct answer and in this case it is.

0
 
LVL 25

Author Comment

by:dgrafx
ID: 22613450
zvonko > the way you are wording it "ONE SPECIFIC FILETYPE" is a bit different than what I actually asked in the first post where I said "a specific filetype" - you are giving it a different meaning.
When I need to ask a question I start with a real basic scenario and see where it goes.
I'm sure you've seen questions where additional info was given down in subsequent posts.
An no - QofQ is not the best solution whether we are talking about one or multiple filetypes.
And yes, it matters not what the end use may be - I was never trying to imply that my use of this validated my answer - I only blogged a bit about my use of it just so you guys had a clearer understanding of what I was doing.
I also stated that I was looking for a regex solution, which if possible for a specific solution, is always faster than a QofQ.

Like I said - I'm not trying to cheat anyone out of points and specifically I would not have bothered IF this had not been a new function in CF8.
Because of this I believe it to be worthy of reopening.
I recall questions from the past (have no idea where they are) that involved this same general concept (except for the end result was different) where a "pre-CF8" work around was given.

Brianmm - I accepted your solution and I can live with it.
And I do care about best solutions.
After reading my reasonings - do you mind if I ask for reopening then accept the regex solution I posted?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22615286
I have tried to test your solution. It did not work for me. Can you show me what test content you used for the var fileTypes?
0
 
LVL 25

Author Comment

by:dgrafx
ID: 22615719
sure
case one : ".jpg"
case two : ".jpg,.gif"
case three : ".jpg,.gif,.png"
et cetera
0
 
LVL 25

Author Comment

by:dgrafx
ID: 22635572
ok - thats fine
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22637625
Hello dgrafx: http:Q_23786327.html
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question