Find the answer to your Linux question:
Results 1 to 6 of 6
Hello everyone, is anyone know a file-browser (template, code, ...) witch I can implement into my c-program (command-line only) functions I need: 1. browsing directory's 2. list files 3. pick ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! JOJBerlin's Avatar
    Join Date
    Sep 2011
    Location
    Berlin
    Posts
    8

    Question commandline filebrowser for c program


    Hello everyone,
    is anyone know a file-browser (template, code, ...) witch I can implement into my c-program (command-line only)

    functions I need:
    1. browsing directory's
    2. list files
    3. pick a file and get the path back

    program is written in c for Linux 2.6

    Thx

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307

  3. #3
    Just Joined! JOJBerlin's Avatar
    Join Date
    Sep 2011
    Location
    Berlin
    Posts
    8

    Question

    Thx for the answer.
    I think you understand me wrong.
    I was looking for code witch allows me to browse through the directory of my hard disk during the runtime of my program.
    hope it is clear now and sorry for my English . . .

  4. #4
    Just Joined!
    Join Date
    Jan 2010
    Posts
    40
    Do you know of Midnight Commander (mc) ?
    It is a very advanced directory browser for text console:
    http://www.thegeekstuff.com/wp-conte...ull-screen.jpg

    Console HT Editor also has some nice directory browser, but it uses some UI style in the vein of TurboVision:
    HT editor | Download HT editor software for free at SourceForge.net

    so browser code probably is quite abstract and complex.

    Then Nano editor uses directory browsing also:
    http://tuxradar.com/files/LXF131.nano.list.jpg

    There is also recovery tool TestDisk for text console, which implements some file browser too:
    http://screenshots.en.softonic.com/e...estdisk-27.jpg

    Note that all these products are licensed as GPL:)

  5. #5
    Just Joined!
    Join Date
    Feb 2009
    Posts
    6
    check this code,

    #include <unistd.h>
    #include <stdio.h>
    #include <dirent.h>
    #include <string.h>
    #include <sys/stat.h>
    #include <stdlib.h>

    void printdir( char *dir, int depth)
    {
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;
    char buf[24];


    if((dp = opendir(dir)) == NULL) {
    fprintf(stderr, "cannot open dirctory: %s\n", dir);
    return;
    }


    // getcwd(buf, 64);
    // printf("getcwd: %s\n", buf);
    // printf("dir: %s\n", dir);

    chdir(dir);
    // getcwd(buf, 64);
    // printf("getcwd: %s\n", buf);
    while((entry = readdir(dp)) != NULL) {
    lstat(entry->d_name, &statbuf);
    if(S_ISDIR(statbuf.st_mode)) {
    if(strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0)
    continue;

    printf("%*s%s\n", depth,"", entry->d_name);

    /* Recurse at a new indent level */
    printdir(entry->d_name, depth+4);

    }
    else
    printf ( "%*s%s\n", depth,"", entry->d_name );
    }
    chdir("..");
    closedir(dp);
    }
    int main()
    {
    printf("Diectory scan of /home:\n");
    printdir("/home", 0);

    exit(0);
    }
    and for more information about this code , please read "Beginning Linux Programming 4th edition", chapter 3: Working with Files

    Hope this will help you.

  6. #6
    Just Joined! JOJBerlin's Avatar
    Join Date
    Sep 2011
    Location
    Berlin
    Posts
    8
    Thx for the answers. I was expecting that there is a framework I simple can implement into my software.
    The functionality from testdisk would be great. But extracting code from an other project is complex like writing it by my own.
    Thx again for trying to help, I think I start with the code above and writing it by my self.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •