execute files from dir

This is a discussion on execute files from dir within the C Programming forums, part of the General Programming Boards category; I took this code from FAQs. And what I wanna to do now is that what is writing out execute. ...

  1. #1
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178

    execute files from dir

    I took this code from FAQs.

    And what I wanna to do now is that what is writing out execute.
    In DIR patches I have lots of .exe patches.
    And now what I wanna to do is some shellexecute or what.
    Something like system("apps.exe");

    So I wanna come into directory and execute all .exe files in it.
    I do not have stranght any more. This is killing me!

    Code:
    #include <dirent.h> 
    #include <stdio.h> 
    
    int main(void)
    {
      DIR           *d;
      struct dirent *dir;                  /* char *path; */
      d = opendir(".");                   /* d = opendir(path) */
      if (d)
      {
        while ((dir = readdir(d)) != NULL)
        {
          printf("%s\n", dir->d_name);       /* something like system(dir->d_name); but this not working for me  */
        }
    
        closedir(d);
      }
    
      return(0);
    }
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    Well you need to make sure d_name is actually an executable file name (.exe)
    The first two entries of readdir are usually "." and ".."

    Plus, are you running windows or linux (or something else?)
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    Quote Originally Posted by Salem
    Well you need to make sure d_name is actually an executable file name (.exe)
    The first two entries of readdir are usually "." and ".."

    Plus, are you running windows or linux (or something else?)
    Yes in folder I got only .exe files. I got lots of Windows patches.

    Curently I am trying to do this for Windows.

    Maybe next week I will try this for Unix. But for Unix I will again look first at FAQ then I will ask you if something goes wrong.
    So dont tell me for Unix!
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  2. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Files not updating in folder
    By BobS0327 in forum Tech Board
    Replies: 4
    Last Post: 06-06-2005, 05:55 PM
  5. C+. List no of files in dir and save to int?
    By stephenturns in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2005, 02:59 AM

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