我只需要一个文件从远程服务器复制到本地PC,如果:文件副本更新
- 本地PC上没有目标文件呢。
- 服务器上的源文件比本地PC上的目标文件更新。
源文件是4 MB,所以我想避免每次都复制。
// File copy if target doesn't exist or source is newer:
if (File.Exists(filenameSource))
{
if (File.Exists(filenameTarget))
{
DateTime dateSource = File.GetLastWriteTimeUtc(filenameSource);
DateTime dateTarget = File.GetLastWriteTimeUtc(filenameTarget);
if (dateTarget < dateSource)
{
File.Copy(filenameSource, filenameTarget, true);
}
}
else
{
File.Copy(filenameSource, filenameTarget);
}
}
我的问题是:
难道上面的代码还是要流4 MB的数据,以获取源的更改的时间标记?
比较修改后的时间戳足以满足我所要做的事情吗?还是我应该比较创建的时间戳?
(#2似乎是一个愚蠢的问题,但如果我把一个新的源文件,修改的时间戳比目标的修改日期和时间旧?)
奖励:
如果我在VBScript中编写上述代码会怎样?下面的代码是否需要传输4 MB的数据才能创建fileSource
对象?
if filesys.FileExists(strSource) then
if filesys.FileExists(strTarget) then
set fileSource = filesys.GetFile(strSource)
set fileTarget = filesys.GetFile(strTarget)
dateSource = fileSource.DateLastModified
dateTarget = fileTarget.DateLastModified
if dateTarget < dateSource then
filesys.CopyFile strSource, strTarget, true
end if
else
filesys.CopyFile strSource, strTarget, false
end if
end if
+1:好吧,我正在解释你的答案,说我可以得到:创建,修改和大小**没有流4 MB **。但是,我需要流4 MB才能计算散列。谢谢! – JohnB 2010-11-12 18:38:54
正确。这正是我所说的。 – Stu 2010-11-12 18:55:48