Directory browsing - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Directory browsing

kkvelankkvelan Posts: 1Member
I want to search or get all the files present in a particular folder. I use findtfirst() and findnext() in Dos. How to do in Linux? I heared somewhere that these two functions are available in Linux too..






Comments

  • sumitxshahsumitxshah Posts: 20Member
    : I want to search or get all the files present in a particular folder. I use findtfirst() and findnext() in Dos. How to do in Linux? I heared somewhere that these two functions are available in Linux too..


    Hi there!,
    Yes, you heard it right. There are function which reads every file in the particular directory. First you have to OPEN the directory then READ that particular directory after that don't forget to CLOSE that directory. And the function name are opendir() readdir() closedir()
    Here is the RUNNING source code for reading each file from a current directory.
    ENJOY............

    #define DIR_2_SCAN "/home/Automation/buffer/"


    void read_dir(void)
    {
    /*local declaration of function. */
    void fun_filter(char filename[100]);
    DIR *dp;
    struct dirent *fnd_file;
    while(1)
    {
    dp = opendir(DIR_2_SCAN);
    if (dp == NULL)
    {
    puts ("*** Couldn't open the directory.");
    exit(0);
    }
    while((fnd_file=readdir(dp))>0)
    {
    if((strlen(fnd_file->d_name))>10)
    fun_filter(fnd_file->d_name);
    }
    (void)closedir(dp);
    sleep(5);
    }
    }
    ____________________________________________________________________
    A winner is not the one who never fails , but the one who never quits.
    Sumit Shah.

Sign In or Register to comment.