FileInfo.CopyTo问题 [英] FileInfo.CopyTo Problem
问题描述
我有一个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
md ****** @ scs-techresources.com
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
推荐答案
试试这个:
http://www.planet-source-code.com/vb...= 556安培; lngWId = 10
Crouchie1998
BA(HONS)MCP MCSE
Try this instead:
http://www.planet-source-code.com/vb...=556&lngWId=10
Crouchie1998
BA (HONS) MCP MCSE
Michael,
当你向我们展示代码时,它应该基本上在我的意见中工作。
要做到这一点,请在程序的顶部设置第一个选项严格。
你现在开始向我们展示一个函数,该函数应该返回一个整数并返回一个布尔值。
你还有一些功能,这是不可能的理解它不会包含它们时的作用。
函数从实例开始用
对于i As Integer = 0到intNumberOfSlots - 1
其中intNumbersOfSlots - 1可以是任何东西
也许你可以给我们发一些代码,这在一开始就不是一个难题。 br />
Cor
Michael,
When you show us code, than it should basicly work in my opinion.
To do that set first option strict to on in top of your program.
You start now with showing us a function which should return an integer and returns a boolean.
As well have you some functions incorporated which is impossible to understand what it does when you don''t inlcude them.
The function start by instance with
For i As Integer = 0 To intNumberOfSlots - 1
Where intNumbersOfSlots - 1 can be anything
Maybe can you sent us some code, that is not at the start already a puzzle.
Cor
Crouchie,
感谢您的帖子,但我只是不明白为什么我的代码会留下一个包含所有文件的文件夹,它们只是空的。任何想法为什么我做了什么并没有给我我想要的东西 - 只是将一个文件复制到另一个文件夹,如果Source更新则覆盖现有文件。
谢谢,
Michael
" Crouchie1998" < CR ********** @ spamcop.net>在留言新闻中写道:#u ************** @ TK2MSFTNGP14.phx.gbl ...
试试这个:
http:// www.planet-source-code.com/vb.../556&lngWId=10
Crouchie1998
BA(HONS)MCP MCSE
Crouchie,
Thanks for the post, but I just don''t understand why my code leaves a folder with all the files there, they just are empty. Any idea why what I did does not give me what I want--simply to copy one file to another folder and over write the existing file if the Source is newer.
Thanks,
Michael
"Crouchie1998" <cr**********@spamcop.net> wrote in message news:#u**************@TK2MSFTNGP14.phx.gbl...
Try this instead:
http://www.planet-source-code.com/vb...=556&lngWId=10
Crouchie1998
BA (HONS) MCP MCSE
这篇关于FileInfo.CopyTo问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!