PowerShell實現的檔案同步指令碼分享

來源:互聯網
上載者:User

   這篇文章主要介紹了PowerShell實現的檔案同步指令碼分享,本文直接給出實現代碼,需要的朋友可以參考下

  ?

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 #分別定義源、目標檔案夾,注意大小寫敏感 $folder_a_path = "D:a" $folder_b_path = "D:b" #遍曆源檔案夾下所有檔案 $folders_a = gci $folder_a_path -Recurse foreach ($folder_a in $folders_a) { #通過替換的方式,取目標檔案的全路徑名稱 $b = $folder_a.fullname.replace($folder_a_path,$folder_b_path) #判斷目標檔案是否存在,如果存在則先判斷新舊 If (test-path $b) { #判斷目標是否為目錄,如果是目錄則跳過,如果不跳過,則會建立一級空目錄 If (!((gi $b).PSIsContainer)) { #判斷目標檔案、源檔案的新舊情況,如果目標已存在檔案的修改時間早於源檔案,則重新拷貝覆蓋 If ((gci $b).lastwritetime -lt $folder_a.lastwritetime) { copy-item $folder_a.fullname $b -force } }   } #如果目標檔案不存在,則直接拷貝 Else { copy-item $folder_a.fullname $b }   }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.