File synchronization script sharing implemented by PowerShell

Source: Internet
Author: User

File synchronization script sharing implemented by PowerShell

This article mainly introduces how to share the file synchronization script implemented by PowerShell. This article provides the implementation code directly. For more information, see

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

# Define the source and target folders respectively. Note the case sensitivity.

$ Folder_a_path = "D: \"

$ Folder_ B _path = "D: \ B"

# All files in the original folder

$ Folders_a = gci $ folder_a_path-Recurse

Foreach ($ folder_a in $ folders_a)

{

# Use the replacement method to obtain the full path name of the target file

$ B = $ folder_a.fullname.replace ($ folder_a_path, $ folder_ B _path)

# Determine whether the target file exists. If yes, determine whether the target file exists.

If (test-path $ B)

{

# Determine whether the target is a directory. skip this step if it is a directory. If it is not skipped, a level-1 empty directory will be created.

If (! (Gi $ B). PSIsContainer ))

{

# Determine the New and Old conditions of the target file and source file. If the modification time of the existing file is earlier than that of the source file, copy and overwrite the file again.

If (gci $ B). lastwritetime-lt $ folder_a.lastwritetime)

{

Copy-item $ folder_a.fullname $ B-force

}

}

 

}

# If the target file does not exist, copy it directly.

Else

{

Copy-item $ folder_a.fullname $ B

}

 

}

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.