# 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 } } |