CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2005
    Posts
    54

    how to delete contents from a file?

    I have created a binary file usinf CFile. Now, i want to delete some of the contents of this file. How to do this?

  2. #2
    Join Date
    Jan 2005
    Location
    germany
    Posts
    160

    Re: how to delete contents from a file?

    Create a new file and copy everything you do not want to delete ... I would propose.

    regards
    HoM

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: how to delete contents from a file?

    You cannot just delete part of a file unless the part to delete is at the end of the file. In that case you can just schrink the filesize to delete that part.
    Otherwise, you need to read everything to memory and only write what you want back to a file or copy the relevant parts to a temporary file first, then delete the original file and move the temporary file to the correct filename.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: how to delete contents from a file?

    You can use CFile::SetLength to reduce the file size.
    Nobody cares how it works as long as it works

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

Featured