Solved

directory count for filetype

Posted on 2008-09-29
16
252 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
  • 7
  • 6
  • 2
16 Comments
 
LVL 11

Accepted Solution

by:
BrianMM earned 500 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Configure IIS to process JSON 10 75
DNS, website, godaddy 6 79
spamming  on Hosted svrs? 6 74
System Analysis 5 52
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now