Thread: Search for *.exe(or *.txt) and than start them

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Question Search for *.exe(or *.txt) and than start them

    Hello,

    is is possible to make a progam which search for *.exe or *.txt etc files on the hard drive.? And than save the results in a variable to start them.
    I have also written a Code which search for the three *.exe files,
    which has been copied to C:\ (Explorer.exe, Calc.exe, Mediaplay.exe). but the program doesnīt start the three programs.

    thanks

    JoJo

    #include <stdio.h>
    #include <dir.h>
    #include <conio.h>
    #include <process.h>


    void main(void)
    {
    struct ffblk ffblk;
    int done;
    printf("Directory listing of *.exe\n");
    done = findfirst("\\*.exe",&ffblk,0);
    while (!done)
    {
    printf(" %s\n", ffblk.ff_name);
    done = findnext(&ffblk);
    spawnlp(P_WAIT, "\\*.exe", "\\*.exe");
    }

    getch();
    }

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Well, if you've got the search written, you can use functions in the FAQ for starting your exe's

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Unhappy

    what FAQ do you mean..from cprogramming? I donīt find an FAQ there.

    JoJo

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    www.cprogramming.com/boardfaq.html

    There's a link to it at the bottom of the page (Board FAQ)... Not the most descriptive name, but whaddyagonnado?

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    ok i found it thanks, and the FAQ show how i have to use the spawn* functions...but how can i combine the spawn* function with the search function to start the *.exe files.
    in other words, whats wrong with my Code....(maybe the whole code..mmhpf)

    JoJo

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Just an idea...

    Have your search function return the filename as a variable, and then just spawn the variable.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    yes that kind of idea i also have got, but the findnext() function saves the results in ffblk or not?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > but the findnext() function saves the results in ffblk or not?
    Yes (didn't you finish reading the manual page?)

    ffblk.ff_name perhaps

    > void main(void)
    int main
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    yuuuuhhu it works thanks, thanks..thanks a lot!!!!

    this is the new code with your great help:

    #include <stdio.h>
    #include <dir.h>
    #include <conio.h>
    #include <process.h>


    int main(void)
    {
    struct ffblk ffblk;
    int done;
    printf("Directory listing of *.exe\n");
    done = findfirst("*.exe",&ffblk,0);
    while (!done)
    {
    printf(" %s\n", ffblk.ff_name);
    done = findnext(&ffblk);
    spawnlp(P_WAIT, ffblk.ff_name, ffblk.ff_name , NULL);
    }
    getch();
    }
    But there is another question i have: Hao can i search the whole hard-drive? With :
    done = findfirst("*.exe",&ffblk,0);
    it search only in the working directory and with ("\\*.exe"...); it search under C:\

    thanks

    JoJo

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > it search only in the working directory and with ("\\*.exe"...); it search under C:\
    1. change the search to "*.*"
    2. to search a directory tree, you need to look at the attributes (one of the members of ffblk). This has a bit set if the current entry is a directory. If its a directory, you need to "chdir" to that directory and start a new search.
    This makes for a nice recursive function.

    > done = findfirst("*.exe",&ffblk,0);
    You also need to change the 3rd parameter to indicate the types of things you want to seach for. 0 just means regular files IIRC.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Thumbs up

    thanks for your help i will try it tomorrow, cause itīs night in germany ....i will post again how it works...good night

    thanks

    JoJo

Popular pages Recent additions subscribe to a feed