下面的代码基本上是一个目录,复制它拉链。在过去的6个月里,这对我来说非常合适
Dim tempMail As String = Temp
Dim startpath As String = tempMail & tvProgress.SelectedNode.FullPath
Dim outMail As String = "c:\LTEMP\"
Dim fileout As String = outMail & tvProgress.SelectedNode.Text
Dim tempfolder As String = "c:\LTEMP" & "\" & tvProgress.SelectedNode.FullPath
Dim Reality As String = "\Reality Stock Report"
Dim enUK As New CultureInfo("en-GB")
Try
Dim x As Integer
Dim q As Integer
Dim inMail As String = FileStr
If CheckInternet() = False Then
MessageBox.Show("No internet connection is detected!" & vbNewLine & vbNewLine & "This job will still be added to completed but you will need to connect to the internet to complete sending this file to CIS", "Internet Connection Check", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
If tvProgress.SelectedNode.Parent.Text = "Archive" Then Call INIDate()
Dim Datey As String = Nothing
If tvProgress.SelectedNode.Parent.Text <> "Archive" Then
Datey = Date.ParseExact(Convert.ToDateTime(tvProgress.SelectedNode.Parent.Text), "dd/MM/yy", enUK)
Else
For q = 0 To UBound(INIdet)
If tvProgress.SelectedNode.Parent.Text = "Archive" Then Datey = INIdet(q).iDate
Next
End If
If My.Computer.FileSystem.FileExists(startpath & Reality & ".docx") Then
Call Word2Pdf(startpath & Reality & ".docx", startpath & Reality & ".pdf")
End If
System.Threading.Thread.Sleep(150)
For x = 0 To UBound(AllDetails)
If AllDetails(x).uName & " - " & AllDetails(x).uCode & " - " & AllDetails(x).uOps = tvProgress.SelectedNode.Text Then
If AllDetails(x).uPlan <> Datey Then
DateCh.Show()
Exit Sub
End If
End If
If AllDetails(x).uName & " - " & AllDetails(x).uCode & " - " & AllDetails(x).uOps & " - " & AllDetails(x).uPlan = tvProgress.SelectedNode.Text & " - " & Datey Then
Application.DoEvents()
My.Computer.FileSystem.CopyDirectory(startpath, tempfolder, True)
Directory.CreateDirectory(fileout & "\")
With tempfolder
For Each xDir As String In Directory.GetFiles(tempfolder)
If Not ((UCase(Path.GetDirectoryName(xDir)).Contains("BACKUP")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("BARS")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("TCMS"))) Then
File.Copy(xDir, Path.Combine(fileout, Path.GetFileName(xDir)), True)
End If
Next
If Directory.Exists(tempfolder & "\Controller") Then
For Each xDir As String In Directory.GetFiles(tempfolder & "\Controller")
If Not ((UCase(Path.GetDirectoryName(xDir)).Contains("BACKUP")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("BARS")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("TCMS"))) Then
File.Copy(xDir, Path.Combine(fileout, Path.GetFileName(xDir)), True)
End If
Next
End If
If Directory.Exists(tempfolder & "\Capcon") Then
For Each xDir As String In Directory.GetFiles(tempfolder & "\Capcon")
If Not ((UCase(Path.GetDirectoryName(xDir)).Contains("BACKUP")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("BARS")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("TCMS"))) Then
File.Copy(xDir, Path.Combine(fileout, Path.GetFileName(xDir)), True)
End If
Next
End If
If Directory.Exists(tempfolder & "\Capcas") Then
For Each xDir As String In Directory.GetFiles(tempfolder & "\Capcas")
If Not ((UCase(Path.GetDirectoryName(xDir)).Contains("BACKUP")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("BARS")) Or (UCase(Path.GetDirectoryName(xDir)).Contains("TCMS"))) Then
File.Copy(xDir, Path.Combine(fileout, Path.GetFileName(xDir)), True)
End If
Next
End If
End With
Dim zip As String = inMail & AllDetails(x).uFile & ".zip"
Dim txt As String = inMail & AllDetails(x).uFile & ".txt"
Dim pdf As String = inMail & AllDetails(x).uFile & ".pdf"
Dim fldr As String = FileStr & AllDetails(x).uFile
ZipFile.CreateFromDirectory(fileout & "\", fileout & ".zip", CompressionLevel.Optimal, False)
My.Computer.FileSystem.CopyFile(fileout & ".zip", ArcFolder & tvProgress.SelectedNode.Text & Date.Parse(AllDetails(x).pDate).ToString(" - dd-MM-yyyy") & ".zip", True)
My.Computer.FileSystem.MoveFile(fileout & ".zip", FileStrOut & tvProgress.SelectedNode.Text & ".zip", True)
My.Computer.FileSystem.DeleteDirectory(fileout, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.DoNothing)
If My.Computer.FileSystem.FileExists(zip) Then
My.Computer.FileSystem.MoveFile(zip, "c:\LTEMP\" & AllDetails(x).uFile & ".zip", True)
End If
If My.Computer.FileSystem.FileExists(txt) Then
My.Computer.FileSystem.CopyFile(txt, ArcFolder & AllDetails(x).uFile & ".txt", True)
My.Computer.FileSystem.MoveFile(txt, "c:\LTEMP\" & AllDetails(x).uFile & ".txt", True)
End If
If My.Computer.FileSystem.FileExists(pdf) Then
My.Computer.FileSystem.MoveFile(pdf, "c:\LTEMP\" & AllDetails(x).uFile & ".pdf", True)
End If
With fldr
If My.Computer.FileSystem.DirectoryExists(fldr) Then
Directory.Delete(fldr, True)
End If
End With
System.Threading.Thread.Sleep(150)
End If
Next
My.Computer.FileSystem.DeleteDirectory(tempMail & tvProgress.SelectedNode.FullPath, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
tvProgress.BeginUpdate()
tvProgress.SelectedNode.Remove()
tvProgress.EndUpdate()
Dim sRoot As String = tempMail
Dim sPath As String = tempMail
DeleteEmptyFolders(sPath, sRoot)
lstPlanned.BeginUpdate()
Call TxtRfrsh()
Call RfshArray()
Call CompleteArray()
Call ltempfiles()
lstPlanned.EndUpdate()
Catch ex As Exception
MsgBox(ex.Message)
End Try
我最近添加了以下代码,它调用了一个将docx文件转换为pdf的例程(单独工作正常)
If My.Computer.FileSystem.FileExists(startpath & Reality & ".docx") Then
Call Word2Pdf(startpath & Reality & ".docx", startpath & Reality & ".pdf")
End If
System.Threading.Thread.Sleep(150)
被叫子
Public Sub Word2Pdf(ByVal infile As String, ByVal outfile As String)
Dim wordApp As Word.Application = Nothing
Try
wordApp = New Word.Application()
wordApp.Documents.Open(infile)
wordApp.ActiveDocument.ExportAsFixedFormat(outfile, Word.WdExportFormat.wdExportFormatPDF)
Finally
If wordApp IsNot Nothing Then
wordApp.Quit()
End If
End Try
End Sub
现在,当满足条件调用上述子版时,我收到Could not complete operation on some files
错误。当我检查目录时,PDF已经被创建,但它没有完成其余的zip和复制例程。
任何想法??
答案 0 :(得分:1)
WordApp可能锁定了其中一个文件。在继续之前,请检查以确保WordApp已完成执行。睡眠(150)显然不够长。