Thread: quick question

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    8

    quick question

    in C how would i make a program copy itself to a certain folder? i cant use the
    system("copy %0 etc..."); command, it doesnt work, know of any command that would work?
    thank you

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    also, (sorry for such dumb questions, i just started C, i used to program in Perl and my C book isnt giving me much help)
    how do i make my program write to a file then save it at a certain place? do i use the fprintf?
    thank you

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    57
    What compiler you are using? I am not sure if system() command works on microsoft platforms. And from "copy" it looks like microsoft platform. Anyways, its a very expensive command.

    Instead you could open the file and copy and write the bytes in binary mode if it executable.

    Anoop.

  4. #4

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    i am using dev c++

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    o and most system commands work on windows platform, but the copy %0 doesnt...

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    i understand the copy function, but how can i get the copy function to reconize the program without giving its pathname, (this is going to be a small installer program) so i wont know where the program will be.... so thats why i am asking is there a C command/function like the batch copy %0 command?

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    no not the name, is there a way to have the program reconize itself then copy itself to a desntination folder??? or can i use that, then add the filename to a string or whatever then have the program copy the program from that string to a folder?

  9. #9
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Originally posted by Salem
    %0 is more like a DOS batch file parameter substitution.

    In C, do something like
    Code:
    char cmd[100];
    sprintf( cmd, "copy %s %s", file1, file2 );
    system( cmd );
    salem? code like that coming from you. What if the file name is extremely long?

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >salem? code like that coming from you. What if the file name is extremely long?
    In C, do something like
    Aside from there being several ways to do just about anything, telling somebody to do "something like" this or that gives us a bit of leeway in the perfection of an example. I've found it saves time. No doubt Salem has also.
    My best code is written with the delete key.

  11. #11
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    can someone please answer my question?
    thank you

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >can someone please answer my question?
    Someone did answer your question. Did you read the replies? Or were you expecting us to write this for you?
    My best code is written with the delete key.

  13. #13
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    no...
    they put how to get the name of the program but not how to make the program copy itself... sorry if im being rude or anything...

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >they put how to get the name of the program but not how to make the program copy itself...
    Maybe I'm seeing something that isn't there, but it sure looks like your question was answered completely.
    In C, do something like
    Code:
    char cmd[100];
    sprintf( cmd, "copy %s %s", file1, file2 );
    system( cmd );
    all the bits you need are in several replies in this thread
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM