MFC file acquisition operations

Source: Internet
Author: User
Tags read ini file
MFC File Operations

 

1. Create the folder createdirectory (% 1, null );
2. Create a cfile file;
File. Open (% 1, cfile: modecreate | cfile: modewrite );
3. Delete the deletefile (% 1 );
4. Delete the folder removedirectory (% 1 );
5. delete all folders in a directory cfilefind finder; cstring path; Path. format ("% s \*. * ", % 1); bool bworking = finder. findfile (PATH );
While (bworking) {bworking = finder. findnextfile (); If (finder. isdirectory () {removedirectory (finder. getfilepath ());}}
6. Clear the folder removedirectory (% 1); createdirectory (% 1, null );
7. Read the file char sread [5120]; cfile mfile (_ T (% 1), cfile: moderead); While (sread! = NULL) {mfile. Read (sread, 5120); cstring % 2 (sread); % 3} mfile. Close ();

8. write File cfile mfile (_ T (% 1), cfile: modewrite | cfile: modecreate); mfile. write (% 2, sizeof (% 2); mfile. flush (); mfile. close ();

10. Read File Attributes DWORD dwattrs = getfileattributes (% 1); If (dwattrs & file_attribute_readonly) {% 2} If (dwattrs & file_attribute_normal) {% 3}

12. enumerate all folders in a directory cfilefind finder; cstring path; Path. format ("% s \*. * ", % 1); bool bworking = finder. findfile (PATH );
While (bworking) {bworking = finder. findnextfile (); If (finder. isdirectory () {cstring % 1 = finder. getfilepath (); % 2 }}

 

 

  • 19 on the 7th floor. Copy all the files in one folder to another directory.

    // # Include

    Using STD: string;

    Char Sep = '/';

    # Ifdef _ Win32

    SEP = '\';

    # Endif

    Cfilefind finder;

    Cstring path;

    Path. Format ("% s \ *. *", % 1 );

    Bool bworking = finder. findfile (PATH );

    While (bworking)

    {

    Bworking = finder. findnextfile ();

    If (! Finder. isdirectory () | finder. isdots ()){

    String S (finder. getfilename ());

    Cstring sourcefile (% 1 );

    If (S. rfind (SEP, S. Length ())! = String: NPOs)

    {

    Sourcefile = sourcefile + "//" + S. substr (I + 1, S. Length ()-I );

    Cstring targetfile (S. substr (I + 1, S. Length ()-I ));

    Targetfile = % 2 + "//" + targetfile /;

    Copyfile (sourcefile. getbuffer (0), targetfile. getbuffer (0), true );

    }

    }

    }

    20. Extract Extension

    Cstring path (% 1 );

    Cstring % 2 = path. mid (path. reversefind ('.'));

    21. Extract file name

    Cstring path (% 1 );

    Cstring % 2 = path. mid (path. reversefind ('\') + 1 );

    22. Extract the file path

    Char appname [max_path];

    Getmodualfilename (null, appname, max_path );

    // # Include

    Using STD: string;

    String S (% 1 );

    String newext (% 2 );

    String: size_type I = S. rfind ('.', S. Length ());

    If (I! = String: NPOs)

    S. Replace (I + 1, newext. Length (), newext );

    Cstring % 3 (s );

     

    33. Read INI file attributes cstdiofile INIFILE (% 1, cfile: moderead); cstring Path = INIFILE. getfilepath (); INIFILE.

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.