Recursive Directory Traversal difficulties

This is a discussion on Recursive Directory Traversal difficulties within the C Programming forums, part of the General Programming Boards category; none...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    11

    Recursive Directory Traversal difficulties

    none
    Last edited by phlook; 03-15-2009 at 10:04 PM. Reason: reposted

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    in case it's being wondered,

    this if the structure of f_info

    Code:
    struct f_info {
      int f_blks[4];  
      int f_scn;
      int f_frg[64];
    };

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    21
    Hey.
    Code:
    char *dir_path;
    ...
    dir_path = strcat(dir,"/");
    dir_path = strcat(dir_path,dp->d_name);
    You've declared a pointer to an array that current has no space allocated. You're trying to write to space you haven't allocated in the above code.

    You could use malloc() to initially allocate space, and realloc to reallocate space (to make it bigger). You'd need to free() the space you allocate eventually.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    I haven't been having any troubles with dir_path, it seems to be not worrying about allocated space. The biggest issue is that if the filesystem looks like

    (root directory)
    file1.c
    file2.txt
    directory
    --dfile1.h
    --subdirectory

    ----sdfile1.html
    ----sdfile2.doc

    --dfile2.php
    file3.mp3


    The traversal will look like:

    read file1.c
    read file2.txt
    open directory
    read dfile1.h

    attempt to open subdirectory
    Error: No such file or directory

    // Execution stops here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  2. Directory traversal issue
    By Mostly Harmless in forum Windows Programming
    Replies: 5
    Last Post: 12-21-2007, 12:44 PM
  3. recursive directory listing help
    By laney69er in forum C Programming
    Replies: 2
    Last Post: 03-13-2006, 01:07 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. recursive matrix traversal
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2001, 11:24 PM

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