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. General Programming
  3. C / C++ / MFC
  4. Deleting a file to recycle bin

Deleting a file to recycle bin

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 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.
  • C Offline
    C Offline
    Chintoo723
    wrote on last edited by
    #1

    How do I delete a file so that it goes to recycle bin, the following code doesnt seem to work? static void delete_file() { SHFILEOPSTRUCT shf; int ret = 0; shf.wFunc = FO_DELETE; shf.pFrom = filename; shf.fFlags = FOF_ALLOWUNDO; if(0 != (ret = SHFileOperation(&shf)) { printf("could'nt delete \"%s\" to recycle bin (err=%d/%ld)\n", filename, ret, GetLastError()); } } thanks!

    J M 2 Replies Last reply
    0
    • C Chintoo723

      How do I delete a file so that it goes to recycle bin, the following code doesnt seem to work? static void delete_file() { SHFILEOPSTRUCT shf; int ret = 0; shf.wFunc = FO_DELETE; shf.pFrom = filename; shf.fFlags = FOF_ALLOWUNDO; if(0 != (ret = SHFileOperation(&shf)) { printf("could'nt delete \"%s\" to recycle bin (err=%d/%ld)\n", filename, ret, GetLastError()); } } thanks!

      J Offline
      J Offline
      Jack Puppy
      wrote on last edited by
      #2

      pFrom must be double terminated. pTo must be set to NULL if not used. Paul DiLascia has a good article on using the Recycle Bin from MSDN April 2001. "My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine

      1 Reply Last reply
      0
      • C Chintoo723

        How do I delete a file so that it goes to recycle bin, the following code doesnt seem to work? static void delete_file() { SHFILEOPSTRUCT shf; int ret = 0; shf.wFunc = FO_DELETE; shf.pFrom = filename; shf.fFlags = FOF_ALLOWUNDO; if(0 != (ret = SHFileOperation(&shf)) { printf("could'nt delete \"%s\" to recycle bin (err=%d/%ld)\n", filename, ret, GetLastError()); } } thanks!

        M Offline
        M Offline
        mbue
        wrote on last edited by
        #3

        This works. char file[MAXPATH]; int ok; int l; strncopy(file,filetodelete,sizeof(file)); shfop.hwnd = GetDesktopWindow(); shfop.wFunc = FO_DELETE; shfop.pFrom = file; l = strlen(shfop.pFrom); if((l+2)

        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