By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

Creating and populating folders in vb.net

P: 9
I have a text file with "|" as a delimeter with three (3) fields

XXX-12345|\\YYYYYYY|\\ZZZZZZZZ

I need to read these files into an output folder. The problem that I'm having is that I need to create folders with the first part of the files (xxx-12345) and place the files \\YYYYYYY AND \\ZZZZZZZZ in this folder. Here is the code that I have so far..

Imports System.IO

Public Class frmRedaction_Copier
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents btnProcess As System.Windows.Forms.Button
Friend WithEvents btnFileFind As System.Windows.Forms.Button
Friend WithEvents btnExit As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents lblSaveFolder As System.Windows.Forms.Label
Friend WithEvents btnOutDir As System.Windows.Forms.Button
Friend WithEvents chkEID As System.Windows.Forms.CheckBox
Friend WithEvents txtFileName_In As System.Windows.Forms.TextBox
Friend WithEvents txtFileName_Out As System.Windows.Forms.TextBox
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
Friend WithEvents txtData As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.btnProcess = New System.Windows.Forms.Button
Me.txtFileName_In = New System.Windows.Forms.TextBox
Me.btnFileFind = New System.Windows.Forms.Button
Me.btnExit = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.lblSaveFolder = New System.Windows.Forms.Label
Me.txtFileName_Out = New System.Windows.Forms.TextBox
Me.btnOutDir = New System.Windows.Forms.Button
Me.chkEID = New System.Windows.Forms.CheckBox
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
Me.txtData = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'btnProcess
'
Me.btnProcess.Location = New System.Drawing.Point(232, 152)
Me.btnProcess.Name = "btnProcess"
Me.btnProcess.TabIndex = 4
Me.btnProcess.Text = "Process"
'
'txtFileName_In
'
Me.txtFileName_In.Location = New System.Drawing.Point(128, 32)
Me.txtFileName_In.Name = "txtFileName_In"
Me.txtFileName_In.Size = New System.Drawing.Size(384, 20)
Me.txtFileName_In.TabIndex = 0
Me.txtFileName_In.Text = ""
'
'btnFileFind
'
Me.btnFileFind.Location = New System.Drawing.Point(528, 32)
Me.btnFileFind.Name = "btnFileFind"
Me.btnFileFind.Size = New System.Drawing.Size(24, 20)
Me.btnFileFind.TabIndex = 1
Me.btnFileFind.Text = "..."
'
'btnExit
'
Me.btnExit.Location = New System.Drawing.Point(376, 152)
Me.btnExit.Name = "btnExit"
Me.btnExit.TabIndex = 5
Me.btnExit.Text = "E&xit"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 24)
Me.Label1.TabIndex = 8
Me.Label1.Text = "Load File"
'
'lblSaveFolder
'
Me.lblSaveFolder.Location = New System.Drawing.Point(24, 88)
Me.lblSaveFolder.Name = "lblSaveFolder"
Me.lblSaveFolder.Size = New System.Drawing.Size(88, 24)
Me.lblSaveFolder.TabIndex = 9
Me.lblSaveFolder.Text = "Output Folder"
'
'txtFileName_Out
'
Me.txtFileName_Out.Location = New System.Drawing.Point(128, 88)
Me.txtFileName_Out.Name = "txtFileName_Out"
Me.txtFileName_Out.Size = New System.Drawing.Size(384, 20)
Me.txtFileName_Out.TabIndex = 2
Me.txtFileName_Out.Text = ""
'
'btnOutDir
'
Me.btnOutDir.Location = New System.Drawing.Point(528, 88)
Me.btnOutDir.Name = "btnOutDir"
Me.btnOutDir.Size = New System.Drawing.Size(24, 20)
Me.btnOutDir.TabIndex = 3
Me.btnOutDir.Text = "..."
'
'chkEID
'
Me.chkEID.Location = New System.Drawing.Point(32, 136)
Me.chkEID.Name = "chkEID"
Me.chkEID.Size = New System.Drawing.Size(104, 16)
Me.chkEID.TabIndex = 12
Me.chkEID.Text = "Rename as EID"
Me.chkEID.Visible = False
'
'txtData
'
Me.txtData.Location = New System.Drawing.Point(32, 208)
Me.txtData.Multiline = True
Me.txtData.Name = "txtData"
Me.txtData.ReadOnly = True
Me.txtData.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtData.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtData.Size = New System.Drawing.Size(592, 128)
Me.txtData.TabIndex = 14
Me.txtData.TabStop = False
Me.txtData.Text = ""
Me.txtData.WordWrap = False
'
'frmRedaction_Copier
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ActiveBorder
Me.ClientSize = New System.Drawing.Size(664, 358)
Me.Controls.Add(Me.txtData)
Me.Controls.Add(Me.chkEID)
Me.Controls.Add(Me.btnOutDir)
Me.Controls.Add(Me.txtFileName_Out)
Me.Controls.Add(Me.lblSaveFolder)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnExit)
Me.Controls.Add(Me.btnFileFind)
Me.Controls.Add(Me.txtFileName_In)
Me.Controls.Add(Me.btnProcess)
Me.Name = "frmRedaction_Copier"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Redaction Copier"
Me.ResumeLayout(False)

End Sub

#End Region



Private Sub btnFileFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileFind.Click

Dim stFileName_In As String
Dim openFileDialog1 As New OpenFileDialog

openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory
openFileDialog1.Title = "Open Text File"
openFileDialog1.Filter = "Text files (*.txt)|*.txt"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then
Dim stFilePathAndName_In As String = openFileDialog1.FileName
Dim MyFile As FileInfo = New FileInfo(stFilePathAndName_In)
stFileName_In = MyFile.Name
Me.txtFileName_In.Text = stFilePathAndName_In
End If


End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub


Private Sub btnOutDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutDir.Click

Dim stFileName_Out As String

SaveFileDialog1.InitialDirectory = System.Environment.CurrentDirectory
SaveFileDialog1.Title = "Save as"
SaveFileDialog1.Filter = "Text files (*.txt)|*.txt"
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.RestoreDirectory = True

If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
Dim stFilePathAndName_Out As String = SaveFileDialog1.FileName
Dim MyFile_Out As FileInfo = New FileInfo(stFilePathAndName_Out)
stFileName_Out = MyFile_Out.Name
Me.txtFileName_Out.Text = stFilePathAndName_Out
End If

End Sub

Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Try

If Me.txtFileName_In.Text = "" Then
MessageBox.Show("Please enter the file name to be processed")
Me.btnFileFind.Focus()
'End If

'If Me.txtFileName_Out.Text = "" Then
'MessageBox.Show("Please enter the output destination")
'Me.btnOutDir.Focus()

Else
Dim fileToRead As String
fileToRead = Me.txtFileName_In.Text

Dim filestream As StreamReader
filestream = File.OpenText(fileToRead)

Dim readcontents As String
readcontents = filestream.ReadToEnd()

Dim textdelimiter As String
textdelimiter = "|"

Dim splitter = Split(readcontents, textdelimiter)

Dim i As Integer

For i = 0 To UBound(splitter)
Me.txtData.Text &= "" & i + 1 & " " & splitter(i) & vbCrLf
Next i

End If


Catch ex As Exception

End Try

End Sub

End Class

How do I acomplish this?
Aug 13 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.