list directory without use ls command?


 
Thread Tools Search this Thread
Top Forums Programming list directory without use ls command?
# 1  
Old 05-22-2004
list directory without use ls command?

Hi
i need C code to list direcoty without using ls command and it sould take the path of the directory from the user?

"please help me it is so important"
# 2  
Old 05-22-2004
#include <stdio.h>
#include <string.h> // for access
#include <fcntl.h>
#include <dirent.h> // for struct dirent
#include <sys/stat.h> //for struct stat and the functions related to it

int main(int argc, char **argv)
{
struct dirent *dp;
DIR *dirp; // structure for the directory

if(argc != 2) {
fprintf(stderr, "Usage: ./a.out dirName");
exit(1);
}

dirp=opendir(argv[1]);
while((dp=readdir(dirp))!= NULL)
printf("%s\n", dp->d_name);
}
# 3  
Old 06-08-2004
thanx for your help but i need that with out using C function also
like "printf(),opendir()", it must use system calls only like "read(),write"
# 4  
Old 06-08-2004
The artificial restriction tells us that this is a homework assignment. If you read the unix.com rules:

https://www.unix.com/unix-for-beginners-questions-and-answers/2971-simple-rules-unix-com-forums.html?s=

... you'll see that homework assignments do not belong here, so I'll close the thread. Tell your teacher what you're having problems with and I'm sure he'll help you out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

2. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

3. Shell Programming and Scripting

Copy list of files from a keyword list to another directory

Hello, I have a folder with a massive amount of files, and I want to copy out a specific subset of the files to a new directory. I would like to use a text file with the filenames listed, but can't get it to work. The thing I'm hung up on is that the folder names in the path can and do have... (5 Replies)
Discussion started by: twjolson
5 Replies

4. Shell Programming and Scripting

Perl Directory List Help

I am currently trying to find all files with extensions .gif .jpg .png .wav and .au in a current directory and count them. I am trying to count them based on there extension only. #!/usr/bin/perl $gif =`ls *.gif | uniq -cf 1`; $jpg =`ls *.jpg | uniq -cf 1`; $png =`ls *.png | uniq -cf 1`;... (2 Replies)
Discussion started by: Temphas
2 Replies

5. UNIX for Dummies Questions & Answers

Command to list our directory size

Is there any command that can list out all the files size including directory in 1 command? `ls` will only give 2048 for a directory, which i'm looking for the actual size. (5 Replies)
Discussion started by: lsy
5 Replies

6. Solaris

How list all directories in a directory?

Hi How can i list all the directories inside a directory? not only the directories in the present dir. also the directories inside directories present in the dirrectory. recursive. "find . -type d" will work with other Unix flavors but not with SunOS. Please help Robin (1 Reply)
Discussion started by: robinbannis
1 Replies

7. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

8. Shell Programming and Scripting

To list files only in a directory

Hi all, I want to list all the files in a directory but not present in the subdirectories. I want the name of each file with its full pathname. ls /opt/cems/log/cemsdbg/db/* /opt/cems/log/cemsdbg/db/securitydb_backup_2009_01_12_06:00:54.log /opt/cems/log/cemsdbg/db/standby_monitor.sql... (5 Replies)
Discussion started by: dipashre
5 Replies

9. UNIX for Dummies Questions & Answers

Directory list inside a directory

Hi Bosses! I have a directory name sih. that directory contains some more directories and some files. i just want to list (ls) the directories under this directory. What will be the command.I am using debian linux. Thanks bosses.will appreciate your help. sih (6 Replies)
Discussion started by: little_jhon
6 Replies

10. UNIX for Dummies Questions & Answers

can we list other than c files in a directory with only 'ls' command?

Guys, can anybody help me in the following........ I have different types(c files,ordinary text files etc) in a directory. is there any way to list other than .c files using the 'ls' command only. i tried with the following. ls *.*. its not listing the .c files,but at the same time not... (3 Replies)
Discussion started by: venkat
3 Replies
Login or Register to Ask a Question