Replace Text Files

(Mod: Split Topic)

Page 1 of 1

10 Replies - 1235 Views - Last Post: 31 March 2012 - 09:24 AM Rate Topic: -----

#1 evnflow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-March 12

Replace Text Files

Posted 31 March 2012 - 02:10 AM

Mentor Edit: Split from Topic

hi, total noob on this, just starting out..any way to do this, but use a replace command instead?..i have populated a checkedlistbox with .txt files and i would like to replace those .txt files with another txt file..any help would be greatly appreciated..

This post has been edited by AdamSpeight2008: 31 March 2012 - 02:14 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Replace Text Files

#2 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Replace Text Files

Posted 31 March 2012 - 03:06 AM

You mean replace the data in the text file? Are you using the StreamWriter to write data to the textfiles?
Was This Post Helpful? 0
  • +
  • -

#3 evnflow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-March 12

Re: Replace Text Files

Posted 31 March 2012 - 05:28 AM

wow, thanks for the quick response...not exactly, i was just wanting to replace the .txt with another .txt that i have in folder..

oops, sorry..just waking up..haha..meant i have .txt files, that i have populated in my checkedlistbox..and able to select them..but i want to be able to "check/select" those files and replace them with a .txt file i have set into a folder..thank you for the help..
Was This Post Helpful? 0
  • +
  • -

#4 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Replace Text Files

Posted 31 March 2012 - 05:29 AM

Both text files have the same name?
Okay, so do you have the code you've written so far? Post it here.

This post has been edited by nK0de: 31 March 2012 - 05:32 AM

Was This Post Helpful? 0
  • +
  • -

#5 evnflow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-March 12

Re: Replace Text Files

Posted 31 March 2012 - 05:31 AM

i have a command button setup, but can only find remove instead of replace..
Was This Post Helpful? 0
  • +
  • -

#6 evnflow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-March 12

Re: Replace Text Files

Posted 31 March 2012 - 06:12 AM

here is the command button command to pull everything up on checkedlistbox:

Private Sub Text_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text.Click
        Dim fbd As New FolderBrowserDialog
        With fbd
            .ShowNewFolderButton = False
        End With
        If fbd.ShowDialog = DialogResult.OK Then
            With CheckedListBox1
                .DataSource = New IO.DirectoryInfo(fbd.SelectedPath).GetFiles("*.txt", IO.SearchOption.AllDirectories)
            End With
            PictureBox1.Image = Image.FromFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Cover.PNG")
        End If
    End Sub


i as trying to find a way once those items are displayed..i hit my "replace" command button and it replaces those .txt files..

would i use something close to this for the replace button:
Dim i As Integer
        For i = lstMiscGoals.Items.Count - 1 To 0 Step -1
            If lstMiscGoals.GetItemCheckState(i) = CheckState.Checked Then
                lstMiscGoals.Items.RemoveAt(i)
            End If
        Next


or


Do While CheckedListBox1.SelectedItems.Count > 0
            CheckedListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
        Loop

but use replace instead of remove?

This post has been edited by modi123_1: 31 March 2012 - 07:41 AM
Reason for edit:: use the code tags

Was This Post Helpful? 0
  • +
  • -

#7 evnflow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-March 12

Re: Replace Text Files

Posted 31 March 2012 - 07:44 AM

I found this..which looks like it will work..but i'm getting errors on str_Source, str_Destination, txtDestination.text and txtSource.text..

Private Sub Text_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text.Click
        str_Source = txtSource.Text
        str_Destination = txtDestination.Text
        If str_Source Is Nothing OrElse str_Destination Is Nothing Then
            MessageBox.Show("SOURCE OR DESTINATION FILE PATH MISSING")
        Else
            If File.Exists(str_Source) = True Then
                If File.Exists(str_Destination) = True Then
                    File.Replace(str_Source, str_Destination, str_backup)
                    MessageBox.Show("Data REPLACED")
                End If
        End If
    End Sub

This post has been edited by AdamSpeight2008: 31 March 2012 - 07:50 AM

Was This Post Helpful? 0
  • +
  • -

#8 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Replace Text Files

Posted 31 March 2012 - 07:51 AM

what are the errors you're getting?

And please use code tags when posting code.
Was This Post Helpful? 0
  • +
  • -

#9 evnflow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-March 12

Re: Replace Text Files

Posted 31 March 2012 - 07:54 AM

sorry about the code..tried to edit it, but can't find the edit button..here it is in code format:

Private Sub Text_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text.Click
        str_Source = txtSource.Text
        str_Destination = txtDestination.Text
        If str_Source Is Nothing OrElse str_Destination Is Nothing Then
            MessageBox.Show("SOURCE OR DESTINATION FILE PATH MISSING")
        Else
            If File.Exists(str_Source) = True Then
                If File.Exists(str_Destination) = True Then
                    File.Replace(str_Source, str_Destination, str_backup)
                    MessageBox.Show("Data REPLACED")
                End If
        End If
    End Sub

Was This Post Helpful? 0
  • +
  • -

#10 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Replace Text Files

Posted 31 March 2012 - 08:05 AM

You still didn't mention the errors you're getting.
These variables str_Source, str_Destination, Have you declared them somewhere else in your code as the type strings?
Was This Post Helpful? 0
  • +
  • -

#11 evnflow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-March 12

Re: Replace Text Files

Posted 31 March 2012 - 09:24 AM

actually scrapped the last code i posted..was confusing the me more than anything..still trying to figure it out how to get the item checked in a checkedlistbox to be replaced by a "test.txt" i have in folder, by a command button..was thinking something similar to this:
CheckedListBox1.Items(CheckedListBox1.SelectedIndex) = Replace("test.txt")
but actually works..haha
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1