Results 1 to 13 of 13

Thread: How do I delete a file in C++?

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Like,
    cout<<Type in the file to delete: ";
    cin>>filepath;
    ???

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use the remove or unlink functions.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Could you please type in the code for that? I can't figure it out.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    #include <stdio.h>
    
    /* ... */
    
    remove("autoexec.bat");
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Or this:
    Code:
    BOOL DeleteFile(
    LPCTSTR lpFileName   // pointer to name of file to delete
    );
    
    DeleteFile(filename);
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That's Windows only
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Ok, thanks, I was trying to figure it out in windows but I couldn't do it. Thanks.
    Alcohol & calculus don't mix.
    Never drink & derive.

  8. #8
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    can you delete any file with that? like even protected system files? And one more thing, if you used that, would a virus scanner pick it up?

    I am not going to write a virus, just wondering how it works.

  9. #9

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Yeah, like remove(some important files), will a virus scanner find it? I was wondering, because it is so simple.
    Alcohol & calculus don't mix.
    Never drink & derive.

  10. #10
    Lively Member
    Join Date
    Jun 2000
    Posts
    122

    It might...

    I don't really know how a virus scanner works, but I am guessing that it monitors only the most important system files. If it monitored every single file, then it would slow the system down considerably. It probably won't do anything if you directly edit them with a text editor or something, but it might pop up if you change them through code. You could try it yourself, but be sure to make a backup of the one you are editing!

  11. #11
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    yeah, well if you just did a full system scan, would it be able to pick up anything?

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  12. #12
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Angry ***

    I cant get it to work....

    remove("jim.zip");


    It no workie

  13. #13
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Cool I spoke too soon!

    Gah, I spoke too soon. I forgot I had to put remove("C:\\Windows\\Desktop\\f-er.zip");

    I was putting:
    remove("C:\Windows\Desktop\f-er.zip")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width