Copy all the objects and files under a certain category to the target category (number of objects)

Source: Internet
Author: User

Recently, you need to create a batch of images.
I used two upload methods.

Method 1:
Function: Copy all objects and files under a certain category to the target category, that is, create a copy of a file catalog.
Idea: first copy all the files under the category, and then follow the example below.
Number 1: The name of the object to be copied (original object). If the object does not exist
Number 2: target object name. If the object does not existProgramWill create

1 Static   Void Directorycopy ( String Sourcepath, String Destpath)
2 {
3 If ( ! Directory. exists (sourcepath ))
4 {
5 // Always
6 Throw   New Directorynotfoundexception ( " The original router did not find " );
7 }
8
9 If ( ! Directory. exists (destpath ))
10 {
11 // Create a project by yourself
12 Directory. createdirectory (destpath );
13 }
14
15 Directoryinfo dir = New Directoryinfo (sourcepath );
16 Directoryinfo [] dirs = Dir. getdirectories ();
17
18 // Copy all the files under the project
19 Copyfile (Dir, destpath );
20
21 If (Dirs. Length > 0 )
22 {
23 Foreach (Directoryinfo temdirectoryinfo In Dirs)
24 {
25 String Sourcedirectoryfullname = Temdirectoryinfo. fullname;
26 String Destdirectoryfullname = Sourcedirectoryfullname. Replace (sourcepath, destpath );
27
28 If ( ! Directory. exists (destdirectoryfullname ))
29 {
30 Directory. createdirectory (destdirectoryfullname );
31 }
32
33 // Copy all files under temdirectoryinfo
34 Copyfile (temdirectoryinfo, destdirectoryfullname );
35
36 // Please refer to the following link for more information:
37 Directorycopy (sourcedirectoryfullname, destdirectoryfullname );
38 }
39 }
40 }

Method 2:
Function: Copy all objects in a specified object
Obtain the information groups of all files under the original object, and copy them in sequence.
Metric 1: category to be copied (original category)
Metric 2: Target metric name

1 Static   Void Copyfile (directoryinfo path, String Destpath)
2 {
3 String Sourcepath = Path. fullname;
4
5 Fileinfo [] files = Path. getfiles ();
6
7 Foreach (Fileinfo File In Files)
8 {
9 // Full name of the original file to be copied
10 String Sourcefilefullname = File. fullname;
11 // Full name of the target file
12 String Destfilefullname = Sourcefilefullname. Replace (sourcepath, destpath );
13 // Start copy file
14 File. copyto (destfilefullname, True );
15 }
16 }

License
Directorycopy (@ "E: \ PC drive", @ "C: \ TEM \ PC drive ");
E: \ PC drive category

 

 

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.