VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This portion of the code looks inside a folder (you can include subfolders too) and changes a speci

by Bobby (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Thu 28th December 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This portion of the code looks inside a folder (you can include subfolders too) and changes a specified file extension to another one. This

Rate This portion of the code looks inside a folder (you can include subfolders too) and changes a speci




Dim fileEntries As String() = Directory.GetFiles(tbBrowse.Text)
        ' Process the list of files found in the directory.
        Dim fileName, ConvTo, ConvFrom As String
        ConvTo = tbExt.Text
        ConvFrom = "." & tbCurExt.Text
        
        For Each fileName In fileEntries
            Dim ff As String = Path.GetExtension(System.Convert.ToString(fileName))
            Dim File1 As String = Path.GetFullPath(System.Convert.ToString(fileName))
            Dim File2 As String
            If ff = ConvFrom Then
                File2 = Path.ChangeExtension(File1, ConvTo)
                File.Copy(File1, File2)
                File.Delete(File1)
            End If


        Next fileName


' if you want VB to also search the subdirectories...

 Dim fileEntries As String() = Directory.GetFiles(tbBrowse.Text)
        ' Process the list of files found in the directory.
        Dim fileName, ConvTo, ConvFrom As String
        ConvTo = tbExt.Text
        ConvFrom = "." & tbCurExt.Text

        For Each fileName In fileEntries
            Dim ff As String = Path.GetExtension(System.Convert.ToString(fileName))
            Dim File1 As String = Path.GetFullPath(System.Convert.ToString(fileName))
            Dim File2 As String
            If ff = ConvFrom Then
                File2 = Path.ChangeExtension(File1, ConvTo)
                File.Copy(File1, File2)
                File.Delete(File1)

            End If

        Next fileName


        Dim subdirectoryEntries As String() = Directory.GetDirectories(tbBrowse.Text)
        '' Recurse into subdirectories of this directory.
        Dim subdirectory As String
        For Each subdirectory In subdirectoryEntries
            'Dim Fold2 As String = Path.GetFullPath(System.Convert.ToString(subdirectory))
            Dim fileEntries2 As String() = Directory.GetFiles(subdirectory)
            ' Process the list of files found in the directory.

            ConvTo = tbExt.Text
            ConvFrom = "." & tbCurExt.Text

            For Each fileName In fileEntries2
                Dim ff As String = Path.GetExtension(System.Convert.ToString(fileName))
                Dim File1 As String = Path.GetFullPath(System.Convert.ToString(fileName))
                Dim File2 As String
                If ff = ConvFrom Then
                    File2 = Path.ChangeExtension(File1, ConvTo)
                    File.Copy(File1, File2)
                    File.Delete(File1)

                End If

            Next fileName

        Next subdirectory

Download this snippet    Add to My Saved Code

This portion of the code looks inside a folder (you can include subfolders too) and changes a speci Comments

No comments have been posted about This portion of the code looks inside a folder (you can include subfolders too) and changes a speci. Why not be the first to post a comment about This portion of the code looks inside a folder (you can include subfolders too) and changes a speci.

Post your comment

Subject:
Message:
0/1000 characters