Solved

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

Posted on 2015-01-22
2
2,270 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

914 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

17 Experts available now in Live!

Get 1:1 Help Now