How do i copy a file?

This is a discussion on How do i copy a file? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Is it possible to make a console application that copies a specified file to another drive? for example to copy ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    23

    Question How do i copy a file?

    Is it possible to make a console application that copies a specified file to another drive? for example to copy C:\useless.txt to A:\

    Please if anyone knows how to do it of its even possible.... reply.

    Thanx
    |:|::...<<VooDoo>>...::|:|

  2. #2
    Unregistered
    Guest
    Code:
    #include <stdio.h>
    
    int main()
    {
    	system("copy file.txt a:\file.txt");
    	return 0;
    }
    ?

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    23

    Doesnt Work

    Im using Dev C++ and it gives me 1 error "implicit declaration of function 'int system(...)'
    |:|::...<<VooDoo>>...::|:|

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    It's in stdlib.h

    Point your cursor at the function name and press F1

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    23

    Angry it doesnt work...

    now it complies without errors but then in the console window it says: The system cannot find the specified file.
    I have the file.txt in the directory but it just wont work. this is the code im using

    ----------------------------------------------------------
    #include <stdlib.h>

    int main()
    {

    system("copy file.txt a:\file.txt");
    system("PAUSE");

    return 0;
    }
    ------------------------------------------------------------
    |:|::...<<VooDoo>>...::|:|

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    23

    It Works Now Thanx

    It Works Now Thanx. i just had to take the file.txt out of "a: file.txt" for future reference the code is.


    #include <stdlib.h>

    int main()

    {
    system("copy file.txt a:");

    return 0;
    }
    Last edited by VooDoo; 07-20-2002 at 02:50 PM.
    |:|::...<<VooDoo>>...::|:|

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    27
    It also works on folders.

    Code:
    #include <stdlib.h> 
    
    int main() 
    
    { 
    system("copy test a:"); 
    system("PAUSE");
    return 0; 
    }
    Thought i would let you know
    Test being your folder.
    Only problem i have found it doesn't copy the folder.

    Also i would like to ask.... would it be possible to be able to make a program that would copy files to a CD-RW? Must be a way but i don't know how.
    Last edited by ChrisMUK; 07-20-2002 at 04:48 PM.

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I wrote a copy program here for someone asking about it on the C board.

    It does the copy using standard C coding (expect for assuming you have backslashes as directory markers in the filenames, which obviously won't work on a *nix box). It's a bit safer than calling system, although a lot more long winded.

    It's not guarenteed to be bullet proof, but it's a start.

    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    If youre going to use \ in a program, double it ( \\) or else it will be called an unknown escape ┐function?

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by civix
    If youre going to use \ in a program, double it ( \\) or else it will be called an unknown escape ┐function?
    I take it you mean this line:
    >if ((p = strrchr(in, '\\')) == NULL)
    The thing is, I did use 2, I wouldn't post code that is that badly broken

    But the board transposed it to a single slash for some reason. So I've edited the post and put 3 slashes in the source of my post, just to make it display 2 to everyone else

    Thanks for pointing it out, at least I know to be careful of this in the future.
    Code:
    Testing : 1 slash : '\'
    Testing : 2 slashes : '\\'
    Testing : 3 slashes : '\\\'
    Testing : 4 slashes : '\\\\'
    Last edited by Hammer; 07-25-2002 at 04:33 AM.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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