Thread: Deleting a file while in a program

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

    Deleting a file while in a program

    Ahm Baahk! Any way, i want to write a program the deletes a file, but i dont know how to do that. Any help? Thanks in advance!
    This war, like the next war, is a war to end war.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    One way is remove().
    Code:
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    int main(void)
    {
       char *filename = "\\dir\\file.txt";
    
       if (remove(filename) == 0)
          cout << "File has been deleted" << endl;
       else
          cout << "Unable to delete file." << endl;
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM