本文介绍了FileInfo.CopyTo问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个Windows VB.Net应用程序,我需要在一个文件夹中保存文件与另一个文件夹中的文件同步。我已粘贴下面的代码。任何人都可以告诉我为什么我最终得到一个文件夹的所有文件名都正确,但每个文件的长度为零。

感谢您的帮助。

Michael


公共功能SyncFiles()作为整数

Dim CopyToPath As String

Dim CopyFromPath As String

Dim CopyToPathFileInfo As FileInfo

Dim CopyFromPathFileInfo As FileInfo


尝试

CopyAllFiles = False

for i As Integer = 0 to intNumberOfSlots - 1

CopyFromPath = AdSlotRecords(i).strPathAndFilenameOfAdClip

CopyFromPathFileInfo =新FileInfo(CopyFromPath)

CopyToPath = AdSlotRecords(i).strPathAndFilenameOfAdClipOnClien t

CopyToPathFileInfo =新FileInfo(CopyToPath)

如果CopyFromPathFileInfo.Exists那么''确保源存在

如果CopyToPathFileInfo.Exists那么''如果目标存在则检查最新版本

如果CopyFromPathFileInfo.LastWriteTime> CopyToPathFileInfo.LastWriteTime然后

CopyFromPathFileInfo.CopyTo(CopyToPath,True)

结束如果

否则

CopyFromPathFileInfo.CopyTo (CopyToPath,True)

结束如果

否则

返回错误

结束如果

下一页

返回True

Catch ex As Exception

返回错误

结束尝试

结束功能


-

Michael D. Murphy

高级软件架构师

SCS-TechResources,Inc。

1400 NW 70 Way

套房HO1

种植园,FL 33313-5330


954-452-1047

Hi,
I have a Windows VB.Net app in which I need to keep files in one folder in sync with files in another folder. I have pasted the code below. Can anyone tell me why I end up with a folder with all the file names correct, but the length of each file is zero.
Thanks for your help.
Michael

Public Function SyncFiles() As Integer
Dim CopyToPath As String
Dim CopyFromPath As String
Dim CopyToPathFileInfo As FileInfo
Dim CopyFromPathFileInfo As FileInfo

Try
CopyAllFiles = False
For i As Integer = 0 To intNumberOfSlots - 1
CopyFromPath = AdSlotRecords(i).strPathAndFilenameOfAdClip
CopyFromPathFileInfo = New FileInfo(CopyFromPath)
CopyToPath = AdSlotRecords(i).strPathAndFilenameOfAdClipOnClien t
CopyToPathFileInfo = New FileInfo(CopyToPath)
If CopyFromPathFileInfo.Exists Then '' Make sure source exists
If CopyToPathFileInfo.Exists Then '' If target exists check for latest version
If CopyFromPathFileInfo.LastWriteTime > CopyToPathFileInfo.LastWriteTime Then
CopyFromPathFileInfo.CopyTo(CopyToPath, True)
End If
Else
CopyFromPathFileInfo.CopyTo(CopyToPath, True)
End If
Else
Return False
End If
Next
Return True
Catch ex As Exception
Return False
End Try
End Function

--
Michael D. Murphy
Senior Software Architect
SCS-TechResources, Inc.
1400 NW 70 Way
Suite HO1
Plantation, FL 33313-5330
md******@scs-techresources.com
954-452-1047

推荐答案




这篇关于FileInfo.CopyTo问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 20:42