#分别定义源, 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
}
}