PowerShell implementation of File synchronization script sharing _powershell

Source: Internet
Author: User
#分别定义源, target folder, note case sensitive
$folder _a_path = "d:\a"
$folder _b_path = "d:\b"
#遍历源文件夹下所有文件
$folders _a = GCI $ Folder_a_path-recurse
foreach ($folder _a in $folders _a)
  {
  #通过替换的方式, take the full path name of the destination file
  $b = $folder _ A.fullname.replace ($folder _a_path, $folder _b_path) 
  #判断目标文件是否存在, if present, first determine the new and old
  if (Test-path $b)
    {
     #判断目标是否为目录, if the directory is skipped, if it is not skipped, an empty directory will be created if
     (! (GI $b). Psiscontainer)
      {
       #判断目标文件, the new and old condition of the source file, and if the target already exists before the file was modified earlier than the source file, the copy overwrite
       if ((GCI $b). Lastwritetime-lt $ Folder_a.lastwritetime)
        {
         copy-item $folder _a.fullname $b-force
        }}}
    
    }
  #如果目标文件不存在, Then direct copy
  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.