473,799 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a file count

Hi Group,

Any ideas how to check for files in a directory, to see if any are of the
same prefix, and make a count of them.

I have a round 100 files, the filename is made up of an engineer number
followed by a contract number.

I want to see how many files each engineer has:

while (! end of list)
{
if (file_name_pref ix == engineer_id)
{
engineer_id++;
}
}

any ideas VERY appreciated.

Many Thanks,

Darren
Nov 13 '05 #1
2 2367
"Darren" <fo*****@world. com> wrote in message
news:85******** *********@newsf ep3-gui.server.ntli .net...
Any ideas how to check for files in a directory, to see if any are of the
same prefix, and make a count of them.
Directories are off-topic here, C as described in the Standard knows nothing
about them. See your compiler's documentation on how to walk a directory on
your operating system.

Checking for a filename prefix, however, is easily done in standard C.
I have a round 100 files, the filename is made up of an engineer number
followed by a contract number.

I want to see how many files each engineer has:
Provided you have built the list using some platform specific extensions,
_and_ provided the definition:

const char engineer_id[] = "ABCD";
while (! end of list)
{
if (file_name_pref ix == engineer_id)
if (strncmp(file_n ame, engineer_id, sizeof engineer_id - 1) == 0) {
engineer_id++;
}
}

any ideas VERY appreciated.


Use strlen instead of sizeof if engineer_id is not constant. (There are two
differences between the two: one syntactical and one semantical. Details
are left as an exercise for you.)

You may also consider changing the logic slightly if the engineer's id is
not at the fixed position in the file name.
Nov 13 '05 #2


Darren wrote:

Hi Group,

Any ideas how to check for files in a directory, to see if any are of the
same prefix, and make a count of them.

I have a round 100 files, the filename is made up of an engineer number
followed by a contract number.

I want to see how many files each engineer has:

while (! end of list)
{
if (file_name_pref ix == engineer_id)
{
engineer_id++;
}
}

any ideas VERY appreciated.

Many Thanks,

Darren


There are probably as many ways of doing this as there are programmers.
Note that for n files, there may be n different engineers.

One way:
-read the entire list
-allocate arrays for n enfineer id's and n counters (preset to zero).
-sort the list (may not be necessary, if the directory read is already
sorted)
-for first item, store engineer id and set counter to 1.
-for each other item in turn, if it has the same engineerid, increment
her counter.
if new id, increment array positions and store id and set new counter
to 1.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4610
by: Pernell Williams | last post by:
Hi all: I am new to Python, and this is my first post (and it won't be my last!), so HELLO EVERYONE!! I am attempting to use "xreadlines", an outer loop and an inner loop in conjunction with "file.tell() and file.seek() in order to navigate through a file in order to print specific lines (for example, every 5th line). Allow me to illustrate by example:
22
61417
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: in_file = raw_input("What is the name of the file you want to open: ") in_file = open("test.txt","r")
68
6833
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
17
2007
by: News | last post by:
Hi everyone, My goal is to pull command switches/options from a file and then assign the values to select variables which would eventually be included in a class object. The data file looks something like this but the switches could be in any order and not all may be used. -m quemanager -s server -p port -k key -o object -c 20 -t test@email.com
9
5212
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still facing problems: Assume that FILE* filePointer; unsigned char lineBuffer;
7
3597
by: theballz | last post by:
Hi, I am learning c programming and come across a problem i cant seem to solve. I have a file which i wish to parse and put certain lines (which do not contain a hash character) into an array and then output the contents of this array. The file seems to be parsed properly and the array gets populated but when I output the array the last line of my text file has filled the array. Text file and code as follows, Text File
24
4458
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone help out a newbie? #include <stdio.h> #include <ctype.h> #include <string.h>
116
4642
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however, when I run it, it stalls and does nothing. I'm wondering if there's something obvious that I'm missing. My code is below and any help would be appreciated. Thanks, Dave
13
10454
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
45
4466
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
0
9540
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.