copying files, exe, mp3, etc

This is a discussion on copying files, exe, mp3, etc within the C++ Programming forums, part of the General Programming Boards category; Im working on a program copyer, file copyer, you know, a copy this file to any file you want... im ...

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    copying files, exe, mp3, etc

    Im working on a program copyer, file copyer, you know, a copy this file to any file you want...

    im using fstream to open, close read, write, etc.

    however, if i copy an exe, music file, or anything other then text, its the same size, looks the same in information, but doesn't work.

    How can i do this?

    Also, how can i view directories...

    Im using Dev C++ for this, though i can do it in Borland Turbo C++ 3, so its in a dos window, instead of windows. Thank you!

    I can show code i have so far, if you need it.


    THANKS IN ADVANCE.....
    AFTER YOU HELP ME, I'LL THANK YOU BEFORE I HAVE YOU HELP ME AGAIN LOL :P
    This war, like the next war, is a war to end war.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Opened in binary mode?
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main(int args,char* argv[])
    {
        if(args != 3)
        {
            cout << "Call: <programmname> <sourceFile> <destinationFile>" << endl;
            return -1;
        }
    
        ifstream fileIn(argv[1],ios::binary);
        ofstream fileOut(argv[2],ios::trunc | ios::binary);
    
        fileOut << fileIn.rdbuf();
    }

  3. #3
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    thanks, but a few questions:

    would that work for binary, text, exes and all perfectly?

    how could i have the user enter in the desired filenames?

    just put some input in there?

    How would i use that so the user could pick the file names? Im kinda new to fstream, i haven't used it much...
    This war, like the next war, is a war to end war.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> im using fstream to open, close read, write, etc.

    Why? I'd just say...
    Code:
    CopyFile(Source, Destination, FALSE);
    ... much easier.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    darn, i cant get it to copy directories....
    does that have to do with the int?
    This war, like the next war, is a war to end war.

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Do you still need the directory in the original place? If not, you can use MoveFile() to effectively rename the directory. This does take all it's children with it.

    CopyFile() won't do that. If you want to copy, create the target directory with CreateDirectory(), then log the original directory with FindFirstFile()/FindNextFile() and use CopyFile() for each file.

    I have a tut on my site for FindFirstFile().

    http://www.adrianxw.dk/SoftwareSite/...irstFile1.html
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    SWEET....

    You've been programming HOW long?
    This war, like the next war, is a war to end war.

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Since 1977.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    *gasp* *drools* whoooaa, ive ben programming C/C++ for 3-4 months now LOL
    This war, like the next war, is a war to end war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. copying jpeg files
    By adk1283 in forum C++ Programming
    Replies: 9
    Last Post: 08-11-2005, 05:44 PM
  2. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 02:51 PM
  3. Copying exe file
    By vasanth in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2002, 02:57 AM
  4. Create exe files
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 09-16-2001, 09:02 PM
  5. copying files
    By gls in forum C Programming
    Replies: 16
    Last Post: 09-06-2001, 01:14 AM

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