Bat+xcopy implementation only copies files that are newer than the target file _dos/bat

Source: Internet
Author: User
Question one: If all files under the C:\a folder are now the same as those under d:\a (date and content of modification)

A file under C:\a was modified by someone else or a file was added!
Can you write a bat to determine if the final modification date for each file under the C:\a folder is not in the first two days! If it is, it is copied to the corresponding directory under D:\a (if it is, overwritten), and if it is not, it is not replicated.

Directory replication:

Copy Code code as follows:

@echo off
echo y|xcopy c:\a/d/e/r/k d:\a\
Pause


Copying files

Copy Code code as follows:

echo y | xcopy C:\index2.htm/d/r/k c:\index.htm


Echo y is the overwrite file, y ok.

For a special award for a versatile decision the original file size was copied

Copy Code code as follows:

@echo off
:: Copy the following page every 5 minutes
for/f%%i in (' dir/b c:\index2.htm ') do (
Set Indexdx=%%~zi
)
If%indexdx% GTR 5120 (
echo y | xcopy C:\index2.htm/d/r/k c:\index.htm
)


Because of the limitations of bat, it is not as strong as the VBS feature, which provides a version of the VBS. Everyone can come here and see.

Tests are not replicated if the target file is the same as the source file. To a certain extent, reduce the read and write to the hard disk.

question two: How does the batch process determine modified date all files and subfolders under the Replication folder

A: Copy all files and subfolders under the current directory to the specified folder, and if the file, folder has the same name but the modified time is different, the latest overwrite old (do not ask if overwrite), if the modified time is not replicated.
For example, copy all fonts under the C Disk font folder (assuming there are subfolders and other types of files under the folder) to the fonts file in H disk, how to achieve the above effect.

B: Copy all files and folders under the current directory to the specified folder (provide the folder name, but do not know the letter), if the file, folder with the same name but the modified time is different, to the latest overwrite old (do not ask if overwrite), if the same modified time does not replicate.
For example, copy all the fonts under the C Disk font folder (assuming there are subfolders and other types of files under the folder) and copy them to the X disk fonts file (x-letter is not sure), and how to achieve the above effect.

Copy Code code as follows:

xcopy *.ttf%1:\fonts\*.*/s/d/y


Do not guess the results, run a look at the results.

xcopy parameter Introduction

Command format: XCOPY source [destination] a bunch of optional parameters
parameter describes
source specifies the file to copy. The
destination Specifies the location and/or name of the new file.
/A copies only the files with the archived attribute set, but does not change the properties.
/M copies only the files that have the archived attribute set and closes the archive attribute. The
/d:m-d-y copies files that have changed after a specified date or a specified date. If no date is provided, only those files with the source time that are newer than the target time are copied.
/exclude:file1[+file2][+file3] ... The
specifies a list of files that contain strings. If there is any string that matches the absolute path of the file to be copied, that file will not be copied.
For example, specifying a string such as \obj\ or. obj excludes all files under directory obj or files with the. obj extension.
/P prompts before each target file is created.
/S replicates directories and subdirectories, except for empty. The
/e replicates directories and subdirectories, including empty. Same as/s/e. Can be used to modify/T.
/V verifies each new file. The
/w prompts you to press the key before copying.
/C Continue copying, even if there are errors.
/I if the target does not exist and more than one file is being copied, assume that the destination must be a directory.
/q does not display the file name when copying.
/F Displays the full source and destination file names when replicating.
/L Displays the files that you want to copy. The
/g allows files that are not encrypted to be copied to a target that does not support encryption. The
/h also copies hidden and system files.
/R overwrites read-only files.
/T Creates a directory structure, but does not copy files. Does not include an empty directory or subdirectories. /T/E includes empty directories and subdirectories.
/U copies only files that already exist in the target. The
/k replication properties. The general Xcopy resets the read-only property.
/n is copied with the generated short name.
/o copies file ownership and ACL information.
/x Copy file Approval settings (implied/O). The
/y Suppresses prompts to confirm overwriting an existing target file. The
/-y causes a prompt to confirm that an existing destination file is overwritten.
/z Replicates network files in restart mode.

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.