how to get path?

This is a discussion on how to get path? within the C Programming forums, part of the General Programming Boards category; hi..... how to get all path names all files in a perticular directory in C pgm. plz tell me...and give ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    9

    Question how to get path?

    hi.....
    how to get all path names all files
    in a perticular directory in C pgm.
    plz tell me...and give some sample pgm.

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    31
    Hi,

    'pgm' means programme I guess...

    You can find information on the standard library functions here:
    http://www.gnu.org/software/libc/man...Directory.html

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by arul View Post

    how to get all path names all files
    in a perticular directory in C pgm.
    Ahhm...the path name for all files in a particular directory would be:

    particular_directory(/ or \)file

    You don't even need a c program!

    But if you meant "all path names (...) in a particular directory" (which would be the directories in the directory, I guess), you could look at dirent.h and readdir. You can get the file type of each file this way and determine if it is a directory.

    If this gives you trouble, post to this thread again.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    There's an FAQ about this, with an example of readdir() and friends, I believe.
    http://faq.cprogramming.com/cgi-bin/...&id=1044780608
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
      char buffer[256];
    
      printf("Input a directory name: ");
      fgets(buffer, sizeof(buffer)/2, stdin);
      strtok(buffer, "\n");
    
      snprintf(buffer + sizeof(buffer)/2, sizeof(buffer)/2, "ls \"&#37;s\"", buffer);
      system(buffer + sizeof(buffer)/2);
    
      return 0;
    }

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    That's just painful. You should put that code in your signature instead of the mere two-plus-buffer-overflow code.

    [edit] I especially like
    Code:
    strtok(buffer, "\n");
    Very well done. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I shouldn't post code like that anymore. I am sometimes taken dangerously seriously and receive PMs such as "Code works great, but how do I capture its output?"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Shortest Path Maze Solver (Breadth Search Help)
    By Raskalnikov in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 07:41 PM
  3. clipping path
    By stanlvw in forum Windows Programming
    Replies: 0
    Last Post: 07-23-2008, 11:47 PM
  4. Path Finding Using Adjacency List.
    By DeepBlackMagic in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2005, 02:34 PM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21