LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Directory travesal program (https://www.linuxquestions.org/questions/programming-9/directory-travesal-program-148881/)

serotonincy 02-21-2004 04:31 PM

Directory travesal program
 
Hi,

Has anyone have any idea how to write a program to traverse thru a directory? I tried but had a false start. I can't even open a directory with "opendir" command to begin with. Is that something to do with permission? But I think I have read, write and execution right for that directory. I'm so totally clueless...

Thanks

german 02-21-2004 04:40 PM

What language are you talking about using

haobaba1 02-22-2004 11:34 AM

Re: Directory travesal program
 
Quote:

Originally posted by serotonincy
Hi,

Has anyone have any idea how to write a program to traverse thru a directory? I tried but had a false start. I can't even open a directory with "opendir" command to begin with. Is that something to do with permission? But I think I have read, write and execution right for that directory. I'm so totally clueless...

Thanks

Are you sure it is a directory you are trying to open? opendir returns null if the name is not a directory, but it may be a file. In the case that it may be a file you need to use the "readdir" function on the directory that contains the file, or current directory, this returns a " struct dirent* ". Successive calls to readdir return the next file in the directory, when the end is reached readdir returns NULL. You use the function "stat" to find out information about the file. The functions "getpwuid"and "getgrgid" return the user id and group id of the owner fo the file. And yes read permissions are needed on the directory.

Hope this helps

chewysplace 02-22-2004 12:42 PM

just do a system call "system("cd /dir");"


All times are GMT -5. The time now is 05:59 AM.