将文件复制到另一个文件夹时出错 [英] Error in copying file to another folder
问题描述
For i As Integer = 0 To _dtCol.Rows.Count
'
Dim nAcctNo As String = String.Empty
nAcctNo = _dtCol.Rows(i).Item(0)
If nAcctNo <> String.Empty Then
Dim AcctNo As String = nAcctNo & "_JAN12.pdf"
Dim sPath As String = AppSettings.Get("UnZipDir")
Dim tPath As String = AppSettings.Get("ZipDir")
Dim nRec As String = sPath & "\" & AcctNo
'-- sample nRec is "C:\eSOA\Unzip\100001600019_JAN12.pdf
Dim tRec As String = tPath & "\" & AcctNo
'-- sample tRec is "C:\eSOA\NewZip\100001600019_JAN12.pdf
If Dir(nRec) <> "" Then ' RECIEVE ERROR HERE "File not found."
System.IO.File.Copy(nRec, tRec, True)
End If
End If
Next
我无法确定错误的真正含义是什么?
请帮帮我.
I could not determine what the error really is?
Please help me.
推荐答案
您是否已调试并逐步完成此步骤?该错误表明该文件不存在...因此这意味着在某个时候您正在设置一个nRec文件,该文件实际上并不存在.
我想知道你的循环.你有
Have you debugged and stepped through this? The error says the file doesn''t exist...so that means at some point you are setting an nRec file that isn''t really there.
I''m wondering about your loop. You have
For i As Integer = 0 To _dtCol.Rows.Count
但我在想你真的想要
but I''m thinking you really want
For i As Integer = 0 To _dtCol.Rows.Count - 1
如果表中有5行,则循环将运行0、1、2、3、4、5.是否确实存在索引为5的行?因为那样我认为您会在此行得到错误:
nAcctNo = _dtCol.Rows(i).Item(0)
因为找不到第5行.
您确实需要调试并逐步了解发生了什么.设置一个断点并使用F10遍历循环.检查并确保已按照您认为的方式设置了nRec和tRec的那些变量.
If you have 5 rows in your table, your loop would run 0, 1, 2, 3, 4, 5. Is there really a row with an index 5?....but this still doesn''t make sense to me because then I think you''d get the error at this line:
nAcctNo = _dtCol.Rows(i).Item(0)
because it wouldn''t find row 5.
You really need to debug and step through to see what is happening. Set a breakpoint and walk through the loop using F10. Check and make sure those variables for nRec and tRec are getting set the way you think they should.
这篇关于将文件复制到另一个文件夹时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!