The VBS implementation replicates only files that are newer than the target file _vbs

Source: Internet
Author: User
Because the site needs frequent updates to the home page, sometimes using a CDN often leads to the home page is generating content when synchronizing data (may be conflict, often lead to the home page is empty), This is the thought of Mr. As a not the first page of the index2.htm and then copied again for the index.htm, so that index2 frequent reading and writing is no problem. So the first to Judge Index2.htm is not empty time to copy, and must be newer than index.htm to copy. This will require some scripting support.

A few days ago wrote a (bat+xcopy to achieve only copy than the target file updates) or appear as empty situation, here Special add some functions, refer to many web site articles, thanks to the results of Baidu is very powerful.

Let's start with a bat version.

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
)



where for/f%%i in (the ' dir/b c:\index2.htm ') do (
Set Indexdx=%%~zi
)
Gets the size of the index2.htm file in bat.

Then through the If%indexdx% gtr 5120 (
Implementation judgment is not greater than 5,120 bytes

The main thing is the following code is more powerful, but also relatively simple

Copy Code code as follows:

Dim FSO
Set fso = CreateObject ("Scripting.FileSystemObject")
Set FN2=FSO. GetFile ("c:\index2.htm")
Flsize2=fn2.size
Fldate2=fn2.datelastmodified
Set FN=FSO. GetFile ("c:\index.htm")
Flsize1=fn.size
Fldate1=fn.datelastmodified
If FSO. FileExists ("c:\index2.htm") and flsize2>50000 and Fldate2>fldate1 Then
Fso.getfile ("c:\index2.htm"). Copy ("C:\index.htm")
If Err.number=0 then WriteHistory "Success" &now (), "Log.txt"
End If

Sub writehistory (hischars, Path)
Const ForReading = 1, ForAppending = 8
Dim FSO, F
Set fso = CreateObject ("Scripting.FileSystemObject")
Set f = fso. OpenTextFile (Path, ForAppending, True)
F.writeline Hischars
F.close
End Sub


There is also the log function, under the current bat can also be. Need to be able to expand on their own.

cloud-dwelling community remote articles, reproduced please indicate the source.

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.