Removing a file

This is a discussion on Removing a file within the C++ Programming forums, part of the General Programming Boards category; I created a program to encrypt/decrypt files. The problem is, it creates a new file for the encryption program. Now ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    16

    Removing a file

    I created a program to encrypt/decrypt files. The problem is, it creates a new file for the encryption program.

    Now I want to remove the unencrypted file.

    I tried:
    Code:
    std::remove(d.filename);
    But it doesn't work. Is there a way to remove a file when you're using a variable as the filename?

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    yes...
    but your sample has missing parts - so it is hard to decide what is your problem

    1. what type is d.filename? if it is std::string you probably need c_str() to pass const char* to remove
    2. have you closed the file before trying to remove it?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    unlink()? (edit: Ah, or remove() Was looking in the wrong section...)

    And note that on most computers, removing a file just removes the links to the data - the actual data itself is not cleared until something else overwrites it.
    Last edited by Cactus_Hugger; 02-24-2008 at 12:11 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    16
    Thanks vart. I got it to work:
    Code:
      source.close();
      std::remove(d.filename.c_str());

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 09:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

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