Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I delete all files in directory using Boost in C++ (unmanaged Windows)?

Posted on 2015-01-22
2
2,518 Views
Last Modified: 2015-01-25
Hi:

I have an unmanaged windows C++ app that's using the boost libraries.

What from the boost filesystem do I use to delete all file's from directory?
I create a Path based on a string path:

Path("c:\\SomePath");

At that point I'm not sure how to delete all the files that reside in that directory.
How do I do this?

Thanks,
JohnB
0
Comment
Question by:jxbma
  • 2
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 40564723
You can do that using the native Windows API, boost isn't required for that. E.g.

SHFILEOPSTRUCT sfo;

ZeroMemory(&sfo,sizeof(sfo));

sfo.wFunc = FO_DELETE;
sfo.pFrom = FilePath;
sfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;

SHFileOperation(&sfo);

Open in new window


to delete a subtree in the file system.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40564742
BTW, if you want to do that with Boos, try 'remove_all()' (http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/reference.html#remove_all), e.g.

boost::filesystem::path p = "c:\\SomePath";

boost::filesystem::remove_all(p);

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall‚Ķ
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question