473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to count number of files in a directory

Hi,

I have a small question.
How do I compute the number of files(which are specific such as .doc) in a directory in C++.

For example, if I have 10 files of type .doc format in a directory, how do I compute this value using C++.

Any help is appreciated.

Thanks!!
Jul 30 '07 #1
6 26834
Hi,

I have a small question.
How do I compute the number of files(which are specific such as .doc) in a directory in C++.

For example, if I have 10 files of type .doc format in a directory, how do I compute this value using C++.

Any help is appreciated.

Thanks!!
I think it depends on OS in which you are working.

If you are on Unix OS then

int i;

i = system(ls -l path/*.doc|wc -l); // here path sholud be complete path
// or path from current directory till the folder where you are
// looking for .doc files.

Regards,
Girish.
Jul 30 '07 #2
sicarie
4,677 Expert Mod 4TB
I think it depends on OS in which you are working.

If you are on Unix OS then

int i;

i = system(ls -l path/*.doc|wc -l); // here path sholud be complete path
// or path from current directory till the folder where you are
// looking for .doc files.

Regards,
Girish.
And in Windows I would imagine it would implement the Win32 API.
Jul 30 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
For Windows, start here.
Jul 30 '07 #4
I am using Windows.

I have gone through the link given above for windows, but could not understand it properly.

Do we have any other methods for it.

Thanks!!
Jul 30 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
You call FindFirstFile and then call FindNextFile until is doesnm;t find a file.

If you are looking for all of the files, then find the *.* file.
Aug 1 '07 #6
ihsahs
1
I think it depends on OS in which you are working.

If you are on Unix OS then

int i;

i = system(ls -l path/*.doc|wc -l); // here path sholud be complete path
// or path from current directory till the folder where you are
// looking for .doc files.

Regards,
Girish.
Hi Girish. Found this forum while searching for a similar problem.I'm working on linux and tried ur code it prints the count value on the console but the return value is 0 on success . I want to assign the count value to a variable, how is it done???
Aug 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: vic | last post by:
Hello, Dean Try this: select distinct c1, c2 into #tmp_1 from t1 select count(*) as cnt from #tmp_1 drop table #tmp_1 With best regards.
0
by: DataFreakFromUtah | last post by:
Hello! No question here, just a procedure for the archive. Search critera: count records imported count data imported count number of rows imported count number of records imported record import...
0
by: Don | last post by:
I intermittently get a runtime Compilation Error that says 'The compiler failed with error code 2000'. It appears that a DLL cannot be found in the 'temporary asp.net files' directory. The...
1
by: Shawn Mehaffie | last post by:
I have an application I want to be able to: 1) Store user specifc settings in ther "My Documents". 2) Store some information in "All Users" document directory. 3) I also want to be able to...
1
by: tranky | last post by:
hi, only one information,please... how to count number of anonymous online users? I use ASP.NET 2.0 thank u tranky
5
by: isabelle | last post by:
hi, every body.. I have two program I couldn’t solve them So, can any body help me. please!! 1-Write a program that accepts a character and count number of occurrences in a file. The file...
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following code to get the recordset of an external database. Dim dbPatients As Database Dim rsCountPatients As Recordset ' to count number of...
5
by: jambonjamasb | last post by:
I am wanting to create a report that summarises the number of items within a date range. For example I have a FIELD called System_Change. This is a drop down COMBOBOX that uses words like unix,...
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.