Solved

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

Posted on 2015-01-22
2
2,066 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now