Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Article Writing
  4. How to delete a file?

How to delete a file?

Scheduled Pinned Locked Moved Article Writing
c++helptutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I'm now writing a program using MFC. I plan to incorporate a file deletion feature into the program. Thank you for your help.

    W L 2 Replies Last reply
    0
    • L Lost User

      I'm now writing a program using MFC. I plan to incorporate a file deletion feature into the program. Thank you for your help.

      W Offline
      W Offline
      Wes Jones
      wrote on last edited by
      #2

      Use Win32 API function: BOOL DeleteFile(LPCTSTR lpFileName)

      PJ ArendsP 1 Reply Last reply
      0
      • W Wes Jones

        Use Win32 API function: BOOL DeleteFile(LPCTSTR lpFileName)

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        I use this function: int RecycleBin (LPCSTR File) { // sends the specified file to the recycle bin. // returns zero on success, non-zero otherwise. char buffer[MAX_PATH]; ::ZeroMemory (buffer, MAX_PATH); strcpy (buffer, File); SHFILEOPSTRUCT fos; ::ZeroMemory (&fos, sizeof (SHFILEOPSTRUCT)); fos.wFunc = FO_DELETE; fos.pFrom = buffer; fos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; return SHFileOperation (&fos); } ;)

        Within you lies the power for good; Use it!

        A 1 Reply Last reply
        0
        • PJ ArendsP PJ Arends

          I use this function: int RecycleBin (LPCSTR File) { // sends the specified file to the recycle bin. // returns zero on success, non-zero otherwise. char buffer[MAX_PATH]; ::ZeroMemory (buffer, MAX_PATH); strcpy (buffer, File); SHFILEOPSTRUCT fos; ::ZeroMemory (&fos, sizeof (SHFILEOPSTRUCT)); fos.wFunc = FO_DELETE; fos.pFrom = buffer; fos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; return SHFileOperation (&fos); } ;)

          A Offline
          A Offline
          AlexMarbus
          wrote on last edited by
          #4

          Pretty cool, I like this function a lot better than ::DeleteFile(..) I think it sucks if an application I wrote just deletes a (any) file, without leaving the user the ability to un-delete it. Although I'd understand you use DeleteFile if your application only write a temporary file (e.g. a spoolfile or whatever) to the 'Temp'-folder. No need to recycle that one. -- Alex Marbus

          1 Reply Last reply
          0
          • L Lost User

            I'm now writing a program using MFC. I plan to incorporate a file deletion feature into the program. Thank you for your help.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            man unlink

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups