open several files and execute?

This is a discussion on open several files and execute? within the C Programming forums, part of the General Programming Boards category; I have an external .exe that will process a single file at a time. The problem is i have several ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    28

    open several files and execute?

    I have an external .exe that will process a single file at a time. The problem is i have several hundreds of files to process, so i wanted to implement some code that allows me to loop an instruction for every file in a directory (all are named *.xyz).

    Any sugestions please?
    Thanks

  2. #2
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    how about a shell script?
    Code:
    FILES=`ls *.xyz`
    for i in $FILES
    do
       my_prog $i
    done
    QuantumPete
    Edit: I just noticed the part about .exe - Are you running this on windows?
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by QuantumPete View Post
    how about a shell script?
    Code:
    FILES=`ls *.xyz`
    for i in $FILES
    do
       my_prog $i
    done
    QuantumPete
    It`s a windows machine

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by autopilot View Post
    It`s a windows machine
    /me scratches his head...
    It's been aeons since I last wrote a batch script... Have a google...

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quick google gave me this:
    Code:
    FOR %%c in (C:\windows\desktop\*.xyz) DO echo %%c
    replace echo with your prog name, put the whole thing in a file with a .bat extension and let rip

    QuantumPete
    Edit: Here's the website: http://home.att.net/~gobruen/progs/d...dos_batch.html
    Last edited by QuantumPete; 09-10-2007 at 04:46 AM. Reason: added site
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by QuantumPete View Post
    Quick google gave me this:
    Code:
    FOR %%c in (C:\windows\desktop\*.xyz) DO echo %%c
    replace echo with your prog name, put the whole thing in a file with a .bat extension and let rip

    QuantumPete
    Edit: Here's the website: http://home.att.net/~gobruen/progs/d...dos_batch.html
    Cool! Problem solved, thank you QuantumPete!

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can also use "explorer" to select a bunch of files and "open" them (either just hitting enter/double-clicking, or using "Open with..." by right-clicking on one of the selected files) - although this assumes that the application takes multiple inputs, rather than just a single file each time.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by autopilot View Post
    Cool! Problem solved, thank you QuantumPete!
    Found another problem...
    Code:
    FOR %%c in (C:\*.pc) DO normfet.exe %%c %%c.txt -nml
    Won`t write anything to %%c.txt(i need the prefix of the original file on the output file). It works if the syntaxe is only "program infile outfile", but the "-nml" wont allow the write of the outfile, although the program runs fine.

    Any ideas?

  9. #9
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    What's the -nml supposed to do?
    Let's the part of your code, where you deal with the arguments

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  10. #10
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by QuantumPete View Post
    What's the -nml supposed to do?
    Let's the part of your code, where you deal with the arguments

    QuantumPete
    the program is not mine (normfet.exe), i am using the executable only.
    "-nml" is one instruction to the program. I run a similar batch script with other programs, it only fails with this one.

  11. #11
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Have you tried putting the -nml at the beginning? Most programs expect their arguments first and then any other files

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  12. #12
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by QuantumPete View Post
    Have you tried putting the -nml at the beginning? Most programs expect their arguments first and then any other files

    QuantumPete
    Yes i tried changing the order but it errors out. What i think is strange is the fact that i can see that the "normfet.exe" is working but still nothing is written.

  13. #13
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Put echo in front of normfat.exe and see whether the arguments that are printed to the screen are the ones that you'd expect.
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  14. #14
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by QuantumPete View Post
    Put echo in front of normfat.exe and see whether the arguments that are printed to the screen are the ones that you'd expect.
    Code:
    Usage: Normfet.exe <infile> <outfile_prefix> [-nml | -bbr ...]

  15. #15
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    I wrote the following:
    Code:
    #include <stdio.h> 
    #include <string.h> 
    
    int main(int argc, char *argv[])
    {
      char child1[] = "normfet.exe";
      char child2[BUFSIZ];
      char child3[BUFSIZ];
      
      // nome saida
      strcpy (child3, argv[1]);
      strcat (child3, "nm");
    
      strcpy (child2, child1);
      strcat (child2, " ");
      strcat (child2, argv[1]);
      strcat (child2, " ");
      strcat (child2, child3);
      strcat (child2, " -nml -ftr");
      
      printf ("Executing %s\n", child2);
      system (child2);
      
      return 0;
    }
    and then used the batch script with
    Code:
    FOR %%c in (C:\3d\*.xyz) DO tnormefet.exe %%c
    but it errors out just before finishing. I guess there is nothing else to do, normfet.exe killed my plans.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2 files 1 project
    By mat13mat in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2008, 08:14 AM
  2. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  3. Files not updating in folder
    By BobS0327 in forum Tech Board
    Replies: 4
    Last Post: 06-06-2005, 05:55 PM
  4. execute files from dir
    By xxxrugby in forum C Programming
    Replies: 2
    Last Post: 04-08-2005, 01:33 PM
  5. how to execute more than one files??
    By myer_784 in forum C Programming
    Replies: 8
    Last Post: 03-15-2005, 10:52 PM

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