API file (folder) Operation Summary: Copy and delete

Source: Internet
Author: User
//  Delete a file or folder  Bool Deletefile ( String  Strpath ){  Int Nlen = Strpath. Length ();  Char * Ppath = New   Char [Nlen + 2  ]; Strcpy (ppath, strpath. c_str (); ppath [nlen + 1 ] = ' \ 0  '  ; Shfileopstruct fileop = { 0  }; Fileop. fflags = //  Fof_allowundo |  //  Allow reuse to recycle bin Fof_noconfirmation | //  No confirmation dialog box appears Fof_noerrorui; //  No error dialog box appears Fileop. pfrom = Ppath; fileop. PTO = NULL; //  It must be null. Fileop. wfunc = fo_delete; //  Delete operation      Bool Bresult = (shfileoperation (& fileop) = 0  ); Delete [] ppath;  Return  Bresult ;}  //  Copy a file or folder  Bool Copyfile ( String Strfrom, String Strto ){  Int Nfromlen = Strfrom. Length ();  Int Ntolen = Strto. Length ();  Char * Pfrom = New   Char [Nfromlen + 2  ];  Char * PTO = New   Char [Ntolen + 2 ]; Strcpy (pfrom, strfrom. c_str (); strcpy (PTO, strto. c_str (); pfrom [nfromlen + 1 ] = '  \ 0  '  ; PTO [ntolen + 1 ] = '  \ 0  '  ; Shfileopstruct fileop = { 0  }; Fileop. fflags = Fof_noconfirmation | // No confirmation dialog box appears Fof_noconfirmmkdir; //  Create a folder directly when needed, without user confirmation Fileop. pfrom = Pfrom; fileop. PTO = PTO; fileop. wfunc = Fo_copy;  Bool Bresult = (shfileoperation (& fileop) = 0  ); Delete [] pfrom; Delete [] PTO;  Return  Bresult ;}  //  Move a file or folder Bool Movefile ( String Strfrom, String  Strto ){  Int Nfromlen = Strfrom. Length ();  Int Ntolen = Strto. Length ();  Char * Pfrom = New   Char [Nfromlen + 2  ];  Char * PTO =New   Char [Ntolen + 2  ]; Strcpy (pfrom, strfrom. c_str (); strcpy (PTO, strto. c_str (); pfrom [nfromlen + 1 ] = '  \ 0  '  ; PTO [ntolen + 1 ] = '  \ 0  '  ; Shfileopstruct fileop = {0  }; Fileop. fflags = Fof_noconfirmation | //  No confirmation dialog box appears Fof_noconfirmmkdir; //  Create a folder directly when needed, without user confirmation Fileop. pfrom = Pfrom; fileop. PTO = PTO; fileop. wfunc = Fo_move;  Bool Bresult = (shfileoperation (& fileop) = 0  ); Delete [] pfrom; Delete [] PTO; Return  Bresult ;}  //  From a named file or folder  Bool Renamefile ( String Strfrom, String  Strto ){  Int Nfromlen = Strfrom. Length ();  Int Ntolen = Strto. Length ();  Char * Pfrom = New  Char [Nfromlen + 2  ];  Char * PTO = New   Char [Ntolen + 2  ]; Strcpy (pfrom, strfrom. c_str (); strcpy (PTO, strto. c_str (); pfrom [nfromlen + 1 ] = '  \ 0  '  ; PTO [ntolen + 1 ] ='  \ 0  '  ; Shfileopstruct fileop = { 0  }; Fileop. fflags = Fof_noconfirmation; //  No confirmation dialog box appears Fileop. pfrom = Pfrom; fileop. PTO = PTO; fileop. wfunc = Fo_rename;  Bool Bresult = (shfileoperation (& fileop) = 0 ); Delete [] pfrom; Delete [] PTO;  Return  Bresult ;} 
 
The shfileoperation operation requires two '\ 0' relative paths, for example, ".. \ x. xml \ 0", including its own \ 0
Additional reading: http://www.vcsos.com/article/pageSource/120216/20120216083823.shtml

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.