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. Delete all files in a folder

Delete all files in a folder

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 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.
  • N Offline
    N Offline
    Nacho Chip
    wrote on last edited by
    #1

    Hello, Can anyone tell me which function I can use to delete all file in a folder. Any standard ANSI C++ function I can used? Thanks!

    Nacho

    J Z H 3 Replies Last reply
    0
    • N Nacho Chip

      Hello, Can anyone tell me which function I can use to delete all file in a folder. Any standard ANSI C++ function I can used? Thanks!

      Nacho

      J Offline
      J Offline
      Joe Woodbury
      wrote on last edited by
      #2

      There are two solutions; one is to get all the files in the directory using findfirst/findnext and then delete them. The other solution is to use the SHFileOperation. Oh, I suppose you could spawn cmd and delete that way, but it's lame.

      Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

      1 Reply Last reply
      0
      • N Nacho Chip

        Hello, Can anyone tell me which function I can use to delete all file in a folder. Any standard ANSI C++ function I can used? Thanks!

        Nacho

        Z Offline
        Z Offline
        Zac Howland
        wrote on last edited by
        #3

        Nacho Chip wrote:

        Any standard ANSI C++ function I can used?

        No. This type of operation will be OS dependent, and will be very different on each system. For Windows, you can use the FindFile API or the Shell interfaces to accomplish this.

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        1 Reply Last reply
        0
        • N Nacho Chip

          Hello, Can anyone tell me which function I can use to delete all file in a folder. Any standard ANSI C++ function I can used? Thanks!

          Nacho

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          See

          WIN32_FIND_DATA      find;
          
          	SetCurrentDirectory("c:\\temp");
          	HANDLE handle=FindFirstFile("*.*",&find);
          	while(FindNextFile(handle,&find)!=0)
          		DeleteFile(find.cFileName);
          or you can use from //SHFileOperation(...);
          	FindClose(handle);
          

          _**


          **_

          WhiteSky


          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