PowerShell实现的文件同步脚本分享
2019/7/10 21:23:08
本文主要是介绍PowerShell实现的文件同步脚本分享,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#分别定义源、目标文件夹,注意大小写敏感 $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 } }
这篇关于PowerShell实现的文件同步脚本分享的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-09-14SharePoint 2019 用 PowerShell将启用发布功能站点网站集另存为模板
- 2022-08-30PowerShell教程 - 程序性能和BUG分析工具
- 2022-08-30PowerShell教程 - 模块管理(Modules Management)
- 2022-08-29PowerShell教程 - Web requests(Web请求)
- 2022-08-26PowerShell教程 - 日期时间管理(Date & Time Management)
- 2022-08-25PowerShell教程 - 磁盘与硬件管理(Disk & Hardware Management)
- 2022-08-25PowerShell教程 - 系统事件管理(System Event Management)
- 2022-08-25PowerShell教程 - 文件系统管理(File System Management)
- 2022-08-24PowerShell教程 - 网络管理(Network Management)
- 2022-08-24PowerShell