as

Monday, 30 June 2014

Code to replicate folders

Below code will replicate the folder files.

Imports System.IO

Public Class Form1


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim p = "f:\fortifiles\"
        Dim d1 = "wakad"
       

        Dim strloc = "chinchwad;moshi"

        'copy dir and all files
        Dim arrLoc = Split(strloc, ";")
        For i As Integer = 0 To UBound(arrLoc)

            Dim d2 = arrLoc(i)
            FileIO.FileSystem.CopyDirectory(p & d1, p & d2, True)
            Call rename(p & d2, d1, d2)
            Call replaceStr(p & d2, d1, d2)
        Next






    End Sub

 

    Sub replaceStr(ByVal dir2, ByVal d1, ByVal d2)



        Dim di = New IO.DirectoryInfo(dir2)
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo
        Dim str, strw As String






        For Each dra In diar1

            str = dra.FullName



            Using sr As New StreamReader(str)

                strw = sr.ReadToEnd()
                strw = Replace(strw, d1, d2, , , CompareMethod.Text)



            End Using

            Using sw As New StreamWriter(str)
                sw.Write(strw)
            End Using



        Next

    End Sub

    Sub rename(ByVal dir2, ByVal d1, ByVal d2)

        Dim di As New IO.DirectoryInfo(dir2)
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo
        Dim Str As String


        'list the names of all files in the specified directory
        For Each dra In diar1

            Str = dra.Name
            Str = Replace(Str, d1, d2, , , CompareMethod.Text)

            'rename all files
            Try
                My.Computer.FileSystem.RenameFile(dra.FullName, Str)
            Catch

            End Try






        Next


    End Sub



End Class


What do you think on this topic? Please express your opinion through comment below. You can write to me at reply2sagar@gmail.com

Sponsored Links

Popular Posts

Comments

ShareThis