function to copy file from one folder to another

This is a discussion on function to copy file from one folder to another within the C Programming forums, part of the General Programming Boards category; Hi, Is there a function that copys a file from a folder to a different folder. I was trying to ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    13

    function to copy MAB file from one folder to another

    Hi,
    Is there a function that copys a file from a folder to a different folder. I was trying to use "rename" but i dont think it takes different source and destination folder. Right now I am opening the source file and writing the contents to the destination file. But since the file is a MAB file the data gets corrupted.
    Last edited by Harman; 05-13-2005 at 11:33 AM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    There's no standard C function to do what you're asking. How does the type of data in the file cause it to get corrupted?
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,552
    > But since the file is a MAB file the data gets corrupted.
    Make sure you open it in "binary" mode then
    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.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    13
    Thanks guys,
    If i read one char at a time it seems to be working so thats what i am going to do.

    [RESOLVED]

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Harman
    Hi,
    Is there a function that copys a file from a folder to a different folder. I was trying to use "rename" but i dont think it takes different source and destination folder. Right now I am opening the source file and writing the contents to the destination file. But since the file is a MAB file the data gets corrupted.
    Sure it does:
    Code:
    int rename(const char *oldpath, const char *newpath);
    However, it isn't 'copying', rather it moves the file.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    If you have a good understanding of dos then you know how to make batch files. have your program make a custom batch file to copy the file. Make sure the batch file deletes itself when it's done. I don't want to write out all the code but I have done it before and it works very well. There may not be a direct route but there is always a route.
    Don't quote me on that... ...seriously

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,552
    Yeah, all those flashing dos-boxes each time you do that sure look impressive to your end user

    What exactly is the difference between opening the file you actually wanted opening, and opening a batch file to open the file for you?
    Apart from being an utter cludge of a solution.
    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.

  8. #8
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    1. You don't see flashing dos-boxes because you are already programming in C which is console based.

    2. Your writing the batch file to copy a file not to open a file.
    Don't quote me on that... ...seriously

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

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