Permanently deleting a file

This is a discussion on Permanently deleting a file within the C++ Programming forums, part of the General Programming Boards category; Okay, so right now im using the remove() function thats in stdio. The problem with that is that the file ...

  1. #1
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605

    Permanently deleting a file

    Okay, so right now im using the remove() function thats in stdio. The problem with that is that the file to be deleted is being moved to the recycle bin. I need to to be deleted permanently, as if it's been emptied from the recycle bin.

    Can anyone help? Thanks in advance.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    remove is standard C function
    standard C is not aware about Recycled Bin which purely windows specific

    So look for some Windows API functions for removing files
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    Eh, its actually a console program that accepts command-line arguments- File shredder.

    I wound up using sprintf() and a system call to do the job.

    Thanks for your time.

  4. #4
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    I use
    Code:
    system("del C:\*\*\* /f");
    It's windows specific.
    EDIT: Or maybe it's 2 backslashes... Not sure.
    Last edited by bradszy; 02-23-2008 at 06:04 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    That will delete all the C drive (files only). Not what you want, is it?
    Using system is most times a bad idea.
    Plus You must use double backslashes \\ to represent a single one in a string.
    "\\" is be interpreted as a \.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    The stars represent sub directories. EG.
    Code:
    system("del C:\\Users\\bradszy\\Desktop\\NewTextDocument.txt");

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Possibly?

    Code:
    #pragma comment( lib, "shell32.lib" ) 
    #include <windows.h>
    #include <shellapi.h> 
    
    int main(void)
    {
        SHFILEOPSTRUCT fos; 
        memset(&fos, 0, sizeof fos); 
        fos.pFrom =  "C:/test.txt";
        fos.wFunc = FO_DELETE; 
        fos.fFlags = FOF_NOCONFIRMATION | FOF_SILENT; 
        SHFileOperation(&fos); 
        return 0;
    }

  8. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    What is wrong with std::remove();. It works fine, and doesn't send anything to the recycle bin.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Or if you have to use the API, RemoveFile.

    But I can't imagine std::remove() sending anything to the bin either.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21