Thread: Deleting files with C++

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Deleting files with C++

    How could do delete any files within C++? Like you run an .exe and some files are deleted, like a game save or something.......example


    c:\games\player1.txt


    and then you want to delete that file.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    I know I know, bad habit

    system("del c:/games/player1.txt");
    I'm sure there are better ways though.

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Thank you.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Or use remove().

    remove("c:\\games\\player1.txt");

    Don't forget you need two backslahes to represent one backslash. Or you can use the forward slash, as Dual-Catfish shows.

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Sorry to bring this up again, but instead of starting a whole new thread I decided to just bump it. How would I delete a whole directory? like ....c:\oldgamefiles\
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    You have to use a function called findnext or something like that. This will find the next file. From here, you can delete the file. Once you have deleted all files inside the directory, you can delete the directory.

  7. #7
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    system("rmdir mydirectory /s /q");

  8. #8
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    I thought it was:

    // for Windows. deltree.exe is found in .../Windows/Command/...
    system(deltree 'directory');

    //use the following to get additional info on deltree.exe
    system(deltree /?);
    think only with code.
    write only with source.

  9. #9
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Thank you guys.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    156

    heres my way

    #include <iostream>
    #include <conio.c> // Thats in Dev-C++4
    #include <stdlib.h>
    #include <stdio.h>
    #include <string>

    void main()
    {
    string directory="C:\\games\files\";
    remove(directory);
    cin.get();
    }
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  11. #11
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Originally posted by toaster
    I thought it was:

    // for Windows. deltree.exe is found in .../Windows/Command/...
    system(deltree 'directory');

    //use the following to get additional info on deltree.exe
    system(deltree /?);

    Would this delete the folder directory or just the files within the folder? How would I go about emptying the contents of a folder and leaving the folder. One more thing what website could I find this neat little "tricks"? because I dont' see any of these things in books.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with loading files into rich text box
    By blueparukia in forum C# Programming
    Replies: 3
    Last Post: 10-19-2007, 12:59 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. fopen vs. _open (for BIG image files)
    By reversaflex in forum C Programming
    Replies: 3
    Last Post: 04-01-2007, 12:52 AM
  4. Permanently deleting files
    By Yasir_Malik in forum Windows Programming
    Replies: 1
    Last Post: 08-01-2006, 10:07 PM
  5. deleting files not in fstream?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2001, 01:36 PM