Thread: I'm back! need help with a simple copy program

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    I'm back! need help with a simple copy program

    I made a really simple program that copys 4 files (defined in teh source code) and copys them to the directory that I specified int eh source code. But I want it so it will copy files you drag on it to the destination defined in the source code. And I want (if possable) to have it so if multiple files were draged on it, it will copy them all to teh directory.

    Sory forgot the question... Is is possible to do that? And if so how? (link or tut or somthing)

    Thank you all very much!

    Oh and was thsi board down yesterday?
    Last edited by Rune Hunter; 10-16-2004 at 04:37 PM.

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    so whats the question? And yes, it was.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    sorry I posted question in first post...

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Code:
    int main(int argc, char* argv[]) {
    
    }
    if you drag files onto your executable the names will be in the argv array.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok here is my code. Some reason it isn't working.


    Code:
    #include <iostream.h>
    #include <Windows.h>
    
    int main(int argc, char* argv[])
    {
        bool test = 0;
        
        CopyFile(
        "argv",
        "C:\\Program Files\\Game_Maker6\\lib\0",
        test
        );
    }
    Please help me...

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    argv is a variable....

    run this and see what happens when you drag files on to it.

    Code:
    int main(int argc, char* argv[]) {
    
      for (int i = 0; i < argc; i++) {
        cout << argv[i] << endl;
      }
      return 0;
    }

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    alright ok it worked now. but now it shows it's self as well. But I will test it a little futhur.

    Thank you lot!

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok so how would I transfer the string to anouther string or somthing so I can atcualy use it were I need to?

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    -well, if its being done in main, you can just use argv[1] to argv[n]

    -if you are using the "string" class you can do a simple assignment:
    string foo = argv[1];

    -if you are using c-strings you'll have to allocate large enough buffers statically or dynamically allocate buffers based on the string size, then you can use "strncpy()" to copy the strings value into the new buffer.

    for your purposes is seems like just using the argv[i] variable should be sufficient unless you need to alter it.

  10. #10
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    thats the thing, I'm not sure how to do teh argv[i]. I only know how to cout it nothing else. That is were I need help.

  11. #11
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    its a variable just like any other variable. you can use each argv[i] for i = 1 to 'argc' as a regular old c-string (1 to argc being the params passed).

    CopyFile( argv[3], "some/path/", 0 ); // copy 3rd file passed

    you might want to consider a loop (similar to how they were printed out) to copy each one.

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I don't know I'm jsutnot getting this. Oh well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need a simple program
    By Peter Griffin in forum C++ Programming
    Replies: 7
    Last Post: 12-04-2005, 04:23 PM
  2. Replies: 5
    Last Post: 11-27-2005, 09:50 PM
  3. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM
  4. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  5. Simple Timer, Call external program,
    By bliss in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2005, 11:21 PM