Myfile Class C ++

Source: Internet
Author: User
Tags strfind

Myfile. h

 # Pragma Once # Include < String > # Include <Windows. h> # Include <Iostream> # Include <Stdio. h> # Include <Io. h> # Include < String > # Include <Shlwapi. h> Using   Namespace STD;  Class  Cmyfile {  Public  :  Explicit Cmyfile ( Void  ); ~ Cmyfile ( Void  );  Static   Void Mycopyfile ( String Sourcefilepath, String  Destfilepath ); Static   Void Mydeletedirectory ( String  Filedir );}; 

Myfile. cpp

# Include "  Stdafx. h  "  # Include  "  Myfile. h  "  Maid (  String  Orig );  Void Copyfilerealize (String Filepath, String Destpath, String  Sourcepatht );  Void Findallfile ( String Sourcepath, String Destpath, String  Sourcepatht );  Bool Deletedirectory (lpctstr lpszdir, Bool  Norecyclebin); cmyfile: cmyfile (  Void ) {} Cmyfile :: ~ Cmyfile ( Void  ){}  ///  //  File to be copied in sourcefilepath  //  Destfilepaht target file  ///  Void Cmyfile: mycopyfile ( String Sourcefilepath, String  Destfilepath) {findallfile (sourcefilepath, destfilepath, sourcefilepath );}  Void Cmyfile: mydeletedirectory ( String  Filedir) {lpcwstr wfilepath = Stringtolpcwstr (filedir); deletedirectory (wfilepath,  True  );}  Void Copyfilerealize ( String Filepath, String Destpath, String  Sourcepatht ){  String Newfilepath = Filepath;  Int Replacelength = sourcepatht. find_last_of ( "  \\  "  ); Newfilepath. Replace (  0  , Replacelength, destpath );  Int Lastindex = newfilepath. find_last_of ( "  \\  "  );  String Destdir = newfilepath. substr ( 0  , Lastindex ); String Destfilename = Newfilepath. substr (lastindex); lpcwstr wfilepath = Stringtolpcwstr (filepath); lpcwstr wdestdir = Stringtolpcwstr (destdir); lpcwstr wdestfilepath = Stringtolpcwstr (destdir + Destfilename );  If (_ Access (destdir. c_str (), 0 ) =- 1  ) {Createdirectory (wdestdir, null);} copyfile (wfilepath, wdestfilepath, false );}  Bool Deletedirectory (lpctstr lpszdir,Bool Norecyclebin = True  ){  Int Len = _ Tcslen (lpszdir); tchar * Pszfrom = New Tchar [Len + 2  ]; _ Tcscpy (pszfrom, lpszdir); pszfrom [Len] = 0  ; Pszfrom [Len + 1 ] = 0  ; Shfileopstruct fileop; fileop. hwnd = NULL; //  No Status display Fileop. wfunc = fo_delete; //  Delete operation Fileop. pfrom = pszfrom; //  Source file name as double NULL terminated string Fileop. PTO = NULL; //  No destination needed Fileop. fflags = fof_noconfirmation | fof_silent; //  Do not prompt the user      If (!Norecyclebin) fileop. fflags | = Fof_allowundo; fileop. fanyoperationsaborted = False; fileop. lpszprogresstitle = NULL; fileop. hnamemappings = NULL;  Int Ret = shfileoperation (& Fileop); Delete [] pszfrom;  Return (Ret = 0  );}  Void Findallfile ( String Sourcepath, String Destpath, String  Sourcepatht ){  Struct  _ Finddata_t fileinfo;  String Strfind = sourcepath + "  \\*  "  ;  Long Handle = _ findfirst (strfind. c_str (),& Fileinfo );  If (Handle =- 1l ) {Cerr < "  Can not match the folder path  " < Endl; exit ( - 1  );}  Do  {  //  Determine whether a subdirectory exists          If (Fileinfo. attrib & _ a_subdir) = _ A_subdir ){  If (Strcmp (fileinfo. Name, "  .  " )! = 0 ) & (Strcmp (fileinfo. Name, "  ..  " )! = 0  )){  String Newpath = sourcepath + "  \\  " +Fileinfo. Name; findallfile (newpath, destpath, sourcepatht );}}  Else  {  String Filepath = sourcepath + "  \\  " + Fileinfo. Name; copyfilerealize (filepath, destpath, sourcepatht );}}  While (_ Findnext (handle, & fileinfo) = 0  ); _ Findclose (handle ); //  Fout. Close ();  } Maid (  String  Orig) {size_t origsize = Orig. Length () + 1  ;  Const Size_t newsize = 100  ; Size_t convertedchars = 0  ; Wchar_t * Wcstring = (wchar_t *) malloc ( Sizeof (Wchar_t) * (orig. Length ()-1  ); Mbstowcs_s ( & Convertedchars, wcstring, origsize, orig. c_str (), _ truncate );  Return  Wcstring ;} 

Cmyfile: mydeletedirectory ("C: \ messer_2.0changshi \ DB ");
Cmyfile: mycopyfile ("C: \ Program Files \ MDB \ DB", "C: \ messer_2.0changshi ");

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.