473,473 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to display all filename of that extension using C

11 New Member
Dear all
Is there any way to show list of filename that we have on that current directory to the user?
Thanks
Jul 21 '06 #1
2 3207
sun99
6 New Member
// displays all the files *.c files is current directory

#include <sys/types.h>
#include <sys/dir.h>
#include <sys/param.h>
#include <stdio.h>

#define FALSE 0
#define TRUE 1

extern int alphasort();
char pathname[MAXPATHLEN];


main() {
int count,i;
struct direct **files;
int filefilter();

if (getwd(pathname) == NULL )
{
printf("Error getting current directory");
exit(0);
}


count = scandir(pathname, &files, filefilter, alphasort);
if (count <= 0)
{
printf( "No files in this directoryn");
exit(0);
}

for (i=1;i<count+1;++i)
printf("%s ",files[i-1]->d_name);
printf("\n");
}

int filefilter(struct direct *entry)
{
char *ptr;


if ((strcmp(entry->d_name, ".")== 0) || (strcmp(entry->d_name, "..") == 0))
return (FALSE);

ptr = rindex(entry->d_name, '.');
if ((ptr != NULL)&& (strcmp(ptr, ".c") == 0) )
return (TRUE);
else
return(FALSE);
}
Jul 22 '06 #2
kujahleague
11 New Member
thank you very much

but my compiler can't seem to find sys/dir.h
is there any way to correct it?
I'm using 2 compilers
DEV C++ (Bloodshed environment)
and also using UNIX GCC to compile the program
Jul 22 '06 #3

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

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
1
by: hokiegal99 | last post by:
I've written a small script (with much help from this list) that searches through a directory for files without a PC filename extension like .doc .xls and then adds them. The reason for writing the...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
27
by: gmtonyhoyt | last post by:
I need assistance coming up with a clean way to handle filename extensions with my application. While I can come up with several ways of doing so on my own, I felt perhaps it would be worth...
3
by: Mullin Yu | last post by:
i've created a console application, and by default the filename will be my project/solution name, ie. testCmd.exe but, can i change it during the build/deployment process to testCmdNew.com ...
1
by: Joe | last post by:
Hi, I have a filename abcxyz.doc. Can someone tell me how do I extract the file extension .doc from the filename in ASP.NET using VB. For your reference a user is typing a filename in the...
5
by: Anders K. Olsen | last post by:
Hello group I'm developing a file application, but I have run into a problem that I hope you can help with. My application lists a number of files (names). Now I would like to display the...
10
by: Brian Gruber | last post by:
Hi, I'm looking for a way to rename a whole directory of files in short order. The files in the directory have different lengths, however all of them end with _xxxx the x's represent a randomly...
8
by: Lad | last post by:
Hello, what is a way to get the the extension of a filename from the path? E.g., on my XP windows the path can be C:\Pictures\MyDocs\test.txt and I would like to get the the extension of the...
3
by: gopal | last post by:
In the SaveFileDialog window, below we have two combo boxes 1.FileName - which lists all the files with specified extension given by us 2.Save as Type - which displays type of file extension...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.