How to delete and copy files?

I know how to use the delete file function, but how do I program in the path of the file? So for example, I have a file called xx.txt and it is located in C:desktopMy_crapMy_Junk; How to you delete it? You would have to specify the path. But I don't know how to do that. Also what is the function for copying files?

--Dave

Comments

  • : I know how to use the delete file function, but how do I program in the path of the file? So for example, I have a file called xx.txt and it is located in C:desktopMy_crapMy_Junk; How to you delete it? You would have to specify the path. But I don't know how to do that. Also what is the function for copying files?
    :
    : --Dave
    :
    [code]
    fclose (fopen ("c:desktop\My_crap\My_Junk\xx.txt", "r+"));
    [/code]
  • [b][red]This message was edited by stober at 2005-5-28 14:24:53[/red][/b][hr]
    : : I know how to use the delete file function, but how do I program in the path of the file? So for example, I have a file called xx.txt and it is located in C:desktopMy_crapMy_Junk; How to you delete it? You would have to specify the path. But I don't know how to do that. Also what is the function for copying files?
    : :
    : : --Dave
    : :
    : [code]
    : remove ("c:desktop\My_crap\My_Junk\xx.txt");
    : [/code]
    :


    there are several ways to copy a file. The easiest is to use the system() function.
    [code]
    char *source_file = "c:desktop\My_crap\My_Junk\xx.txt";
    char *destination_file = "c:desktop\My_crap\My_Junk\duplicate.txt";

    char command[255];
    sprintf(command,"copy %s %s",source_file,destination_file);
    system(command);
    [/code]




  • using C++ iostream should be easiest:

    #include
    #include

    int main() {
    ifstream in("c:desktop\My_crap\My_Junk\xx.txt");
    ofstream out("c:desktop\My_crap\My_Junk\duplicate.txt");
    out<<in.rdbuf(); // copy file
    in.close();
    out.close();
    }
  • :
    : using C++ iostream should be easiest:
    :
    : #include
    : #include
    :
    : using namespace std;
    :
    : int main() {
    : ifstream in("c:desktop\My_crap\My_Junk\xx.txt");
    : ofstream out("c:desktop\My_crap\My_Junk\duplicate.txt");
    : out<<in.rdbuf(); // copy file
    : in.close();
    : out.close();
    : return 0;
    : }
    :

  • Thanks alot!

    Digga
  • How does that work? first reads the whole file into memory then writes it out to the output file? Great for small files, but won't work on large ones if the file is larger than available memory.

  • Good question haven't thought about that.
    I just used the example in the book ( Bruce Eckel's Thinking in C++ volume Two : Practical programming page 178 ) as a base.
    I suppose that with real big files virtual memory (hard disk based memory) is used. I suppose this should be a compiler/hardware issue and
    of no concern to the programmer.
    If I read the piece in Bruce Eckels's book about iostream buffering/
    streambuf/rdbuf, I cannot find anything about restrictions when using these items.
    But I am not really sure, I'm just guessing.

  • :
    : Good question haven't thought about that.
    : I just used the example in the book ( Bruce Eckel's Thinking in C++ volume Two : Practical programming page 178 ) as a base.
    : I suppose that with real big files virtual memory (hard disk based memory) is used. I suppose this should be a compiler/hardware issue and
    : of no concern to the programmer.
    : If I read the piece in Bruce Eckels's book about iostream buffering/
    : streambuf/rdbuf, I cannot find anything about restrictions when using these items.
    : But I am not really sure, I'm just guessing.
    :
    :


    The operative system has got specific functions for file copy, which are probably more effectivly implemented than the open/read file functions.
    If you use fopen() the compiler doesn't know what you are going to do with the file, so it can't choose the most effective function.

    The ANSI C standard has no way to copy a file effectivly, which could be because they talk about streams, not files. On the other hand that argument is stupid, because there are functions like remove(), rename(), tmpfile() etc. So it seems there is no logical explanation to why that function is missing.

    If you want to copy a file effectivly, you must fall back to the OS specific code, like system("copy file.txt");

    Or in Windows, preferably use the CopyFile() function.
  • Using http://www.duplicatefilter.com is a good and easy way to find and delete duplicate files on hard drives.

  • sonhousonsonhouson USA
    edited January 2014

    For various reasons, you may lost data on Mac, such as accidental deletion, computer crash, virus infection, improper formatting, and other operations.On the surface, you can no longer recover those lost files, actually, all of those lost data or formatted/deleted files are still on your Mac.However,you must to use a professional Data Recovery for Mac to recover deleted files in Mac.
    There are several utilities available to help recover deleted files under Mac OS X. Your chances of success depend on how the file was deleted or lost.

  • juddyarejuddyare HongKong
    edited June 2014

    Well, to permanent erase deleted data from iPhone, simple deletion, will leave the possibility of recovery, threat to your data security.Want to permanently remove all the data like contacts, messages, call history, apps, system setting, photo, video, keyboard cache, safari bookmark,e-mail, etc on your iPhone,iPod or iPad before donate, resell, or trade it in? Whether it is for security reasons, or want to save time, I strongly recommend to use iPhone Data Eraser.

    iPhone Data Eraser is designed to delete iPhone data thoroughly and what’s worth mentioning is that those deleted iPhone data cannot be recovered any more. It wins a lot of applauses with this extraordinary feature. So you can sell your old iPhone with a peaceful mind after you have deleted all your provide information with the help of iPhone Data Eraser.
    image

    How to Delete Contacts from iPhone Permanently

    How to Permanent Deleted Videos from iPad

    How to Permanent Deleted Data from iPhone

  • If you want to Recover Deleted Files on Android, Android Data Recovery is one of the most professional data recovery tool. It can help you retrieve all kinds of common file types lost due to factory resetting, accidentally deleting, formatting, and other unknown reasons. Previewing and selectly restoring your wanted files from your device is also allowed in this program. You can use it to recover deleted photos from android phone as well as videos, messages and more. Now, follow the steps to recover them easily.

    More information:
    How to Retrieve deleted contacts from android

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories