Solved

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

Posted on 2015-01-22
2
2,980 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

691 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