listing files question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers listing files question
# 1  
Old 01-15-2009
listing files question

hello im new to linux programming trying to list files in a directory i current have the code to list all the files but i do not want the hidden files to show such as a file named .openoffice.org2.0 for example, can anyone help me or point me in the right direction


#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
int recls(void);
int main(void){
recls();
}
int recls(void) {
DIR *dir;
struct dirent *dirslot;
dir=opendir(".");
while (1) {
dirslot=readdir(dir);
if (dirslot==NULL) return 1;
printf("%s\n", dirslot->d_name);
}
}
# 2  
Old 01-15-2009
Code:
        while (1) {
                dirslot=readdir(dir);
                if (dirslot==NULL) return 1;
+               if (dirslot->d_name[0] == '.') {
+                       continue;
+               }
                printf("%s\n", dirslot->d_name);
        }
 }

# 3  
Old 01-15-2009
thank you for you help, it now works fine Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Formatted Directory Listing Question

Greetings to you. I have a quick question for the community today ;) I'm interested in the following format for recursive output from a command such as "ls" or "dir" when pointed to a folder: ...but there doesn't seem to be coverage for this type of output formatting in the manpages. Maybe... (11 Replies)
Discussion started by: LinQ
11 Replies

2. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

3. Shell Programming and Scripting

Simple listing directory question

I have a very basic question: How do I list all the directories in the following order? If I do ls -l I get different results than I want to achieve. dir.1 dir.2 dir.3 dir.4 dir.5 dir.6 dir.7 dir.8 dir.9 dir.10 dir.11 dir.12 dir.13 dir.14 (4 Replies)
Discussion started by: jville
4 Replies

4. SCO

CPIO listing from tape question...

Hi. I have this old server onto which i needed to list the content of a tape. This is a SCO box (SCO_SV 3.2 5.0.6 i386) and backup was done using cpio. #tape status status : ready beginning-of-tape soft errors : 0 hard errors : 0 underruns : 0 #dtype /dev/rct0 /dev/rct0 ... (5 Replies)
Discussion started by: Stephan
5 Replies

5. Shell Programming and Scripting

perl script for listing files and mailing the all files

Hi, I am new to perl: I need to write perl script to list all the files present in directory and mail should be come to my inbox with all the files present in that directory. advanced thanks for valuable inputs. Thanks Prakash GR (1 Reply)
Discussion started by: prakash.gr
1 Replies

6. UNIX for Dummies Questions & Answers

listing certain files

How would i list the files that begin with a and end with .erc with 4 characters between (5 Replies)
Discussion started by: trob
5 Replies

7. UNIX for Advanced & Expert Users

listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file. Sample control file: TEST SEND SFFFILE CONTL The directory contains followign... (15 Replies)
Discussion started by: ukatru
15 Replies

8. UNIX for Dummies Questions & Answers

Quick listing question

Just a quick question. Is there a command that just lists the folders in a directory. I know of 'ls -p' that shows the directories with a '/' at the end. Though i would just like to have a list of the folders instead of everything else in that folder. Thanks (3 Replies)
Discussion started by: Jaken
3 Replies

9. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

10. UNIX for Dummies Questions & Answers

Another Listing Question

If I had a bunch of files called: report06/02/99, report 06/09/00, report07/08/00, report0608/99. How would I be able to list only the files that begin with "report" for the month of June 1999. It's for my shell scripting program. Thanks in advance. b (1 Reply)
Discussion started by: Astudent
1 Replies
Login or Register to Ask a Question