Use boost: filesystem to operate files

Source: Internet
Author: User
// Boosttest. cpp: defines console applications. Program . // # Include "stdafx. H "# include" Boost/filesystem. HPP "// includes all needed boost. filesystem declarations # include <iostream> // for STD: coutusing namespace boost: filesystem; using namespace STD; # include <boost/filesystem. HPP> # include <vector> # include <string> # include <iostream> namespace FS = boost: filesystem; void getallfileofpath (STD: String strpath, STD :: vector <STD: String> & dllnames) {FS: path F Ullpath (FS: initial_path (); // initialize this project path fullpath = FS: system_complete (FS: path (strpath, FS: Native )); // convert relative paths to absolute paths // Note: fullpath is feasible if (! FS: exists (fullpath) // check whether the specified directory exists {STD: cout <"cannot be found. Check whether the directory exists:"; STD :: cout <fullpath. native_file_string () <STD: Endl; // output path name return;} If (! FS: is_directory (fullpath) // whether the directory is {STD: cout <"the specified path is not a directory"; STD: cout <fullpath. native_file_string () <STD: Endl; return;} FS: directory_iterator end_iter; For (FS: directory_iterator file_itr (fullpath); file_itr! = End_iter; ++ file_itr) {If (! FS: is_directory (* file_itr) & (FS: Extension (* file_itr )! = ". EXE ") // file suffix {dllnames. push_back (file_itr-> leaf (); // get file name }}int main () {try {string P ("C: /tddownload/Yue Quan Chuan/fdsaf "); STD: vector <STD: String> dllnames; getallfileofpath (p, dllnames); STD :: vector <STD: String >:: iterator itr = dllnames. begin (); For (; itr! = Dllnames. end (); ++ itr) {STD: cout <* itr <STD: Endl; remove (p + "/" + * itr );}} catch (exception & E) {cout <E. what () <Endl ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.