Deleting a file? Need help...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cosmos22
    New Member
    • Feb 2008
    • 9

    Deleting a file? Need help...

    Hello, I am pretty new to C++, and I have a question:

    I am, and have been using Dev-C++

    I used this code, to delete a text file on my desktop. The first time around, it worked perfectly. Given the file example name of "dafile".


    #include <stdlib.h> // needed to use system() function

    int main() {
    system("del dafile.txt");
    return 0;
    }


    I compiled the file, and ran it, it worked. However, later on, I used the same code, ran it in the same conditions and nothing happened at all.

    This system command worked fine the first time around, I have no idea what I have done wrong.

    I have tried running this on other computers, in the same conditions, and nothing worked. Has it anything to do with the complied data? There was no errors when I checked it the second time...


    Thank you.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by cosmos22
    Hello, I am pretty new to C++, and I have a question:

    I am, and have been using Dev-C++

    I used this code, to delete a text file on my desktop. The first time around, it worked perfectly. Given the file example name of "dafile".


    #include <stdlib.h> // needed to use system() function

    int main() {
    system("del dafile.txt");
    return 0;
    }


    I compiled the file, and ran it, it worked. However, later on, I used the same code, ran it in the same conditions and nothing happened at all.

    This system command worked fine the first time around, I have no idea what I have done wrong.

    I have tried running this on other computers, in the same conditions, and nothing worked. Has it anything to do with the complied data? There was no errors when I checked it the second time...


    Thank you.
    The del command refers to the file in the current directory .
    I hope that you are referring to the file in the desktop?
    If you need you can use remove command also from the C code to remove the file
    Raghuram

    Comment

    Working...