hello, what i am working on is a project that will take a files based on finding an index of a variable in the file name. it will copy and move those files to a new location with a new name.
i have the project working perfectly however when i got to the next part of the program it's throwing everything for a loop.
the files start off as .mdoc files that look something like this "code_2013033199_title.mdoc" if i manually go to that file i can right click and extract a perfect pdf of that file.
using my program after the file has been identified and moved it looks like this "code_Q12013_title.mdoc". now if i go to that file and right click to extract it i get a pcl file. I'm not sure why.
here is my code for the copy, rename and move piece.
Public Sub btn_SearchMdocs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SearchMdocs.Click
Dim quarter As String = tb_QuarterSelected.Text
If (quarter) = 0 Then
MsgBox("Please select a quarter before continuing.")
Exit Sub
End If
'defines what to look for in file name
Dim pattern As String = "*" & quarter & "*"
'sets file directories to move files from/to
Dim QtrsourceDir As String = G.StoreroomDirectory
Dim QtrdestDir As String = G.StagingDirectory
QtrdestDir = QtrdestDir.Replace("\\", "\\")
Dim fileCount As Integer = 0
'finds fiels, numbers them and then moves them and renames them if they are not in secureview company set
For Each f As String In Directory.EnumerateFiles(QtrsourceDir, pattern, SearchOption.AllDirectories)
Dim fileName As String = Path.GetFileName(f)
Dim ind As Integer = fileName.IndexOf("_" & quarter)
Dim code As String = fileName.Substring(0, ind)
Dim Qname As String
If (quarter.Substring(4, 2)) = "03" Then
Qname = "Q1"
End If
If (quarter.Substring(4, 2)) = "06" Then
Qname = "Q2"
End If
If (quarter.Substring(0, 6)) = "09" Then
Qname = "Q3"
End If
If (quarter.Substring(0, 6)) = "12" Then
Qname = "Q4"
End If
fileName = fileName.Replace(quarter, Qname & quarter.Substring(0, 4))
Dim destFile As String = QtrdestDir & code & fileName.Substring(ind)
For Each item As Object In lb_M3test.Items
If item.ToString = code Then
File.Copy(f, destFile)
fileCount = fileCount + 1
End If
Next
Next
tb_CountMDOC.Text = fileCount
End Sub
any help that anyone can offer would be fantastic.
thank you!
Brian
i have the project working perfectly however when i got to the next part of the program it's throwing everything for a loop.
the files start off as .mdoc files that look something like this "code_2013033199_title.mdoc" if i manually go to that file i can right click and extract a perfect pdf of that file.
using my program after the file has been identified and moved it looks like this "code_Q12013_title.mdoc". now if i go to that file and right click to extract it i get a pcl file. I'm not sure why.
here is my code for the copy, rename and move piece.
Public Sub btn_SearchMdocs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SearchMdocs.Click
Dim quarter As String = tb_QuarterSelected.Text
If (quarter) = 0 Then
MsgBox("Please select a quarter before continuing.")
Exit Sub
End If
'defines what to look for in file name
Dim pattern As String = "*" & quarter & "*"
'sets file directories to move files from/to
Dim QtrsourceDir As String = G.StoreroomDirectory
Dim QtrdestDir As String = G.StagingDirectory
QtrdestDir = QtrdestDir.Replace("\\", "\\")
Dim fileCount As Integer = 0
'finds fiels, numbers them and then moves them and renames them if they are not in secureview company set
For Each f As String In Directory.EnumerateFiles(QtrsourceDir, pattern, SearchOption.AllDirectories)
Dim fileName As String = Path.GetFileName(f)
Dim ind As Integer = fileName.IndexOf("_" & quarter)
Dim code As String = fileName.Substring(0, ind)
Dim Qname As String
If (quarter.Substring(4, 2)) = "03" Then
Qname = "Q1"
End If
If (quarter.Substring(4, 2)) = "06" Then
Qname = "Q2"
End If
If (quarter.Substring(0, 6)) = "09" Then
Qname = "Q3"
End If
If (quarter.Substring(0, 6)) = "12" Then
Qname = "Q4"
End If
fileName = fileName.Replace(quarter, Qname & quarter.Substring(0, 4))
Dim destFile As String = QtrdestDir & code & fileName.Substring(ind)
For Each item As Object In lb_M3test.Items
If item.ToString = code Then
File.Copy(f, destFile)
fileCount = fileCount + 1
End If
Next
Next
tb_CountMDOC.Text = fileCount
End Sub
any help that anyone can offer would be fantastic.
thank you!
Brian