Iterating Through & Renaming Files.

Posted on 2004-11-17
Last Modified: 2010-04-23
Just after how to do a couple of things.

1. Iterate through a directory file by file and get the filename.

2. Rename a file.

Thanks in Advance :)
Question by:jazduck
    LVL 96

    Accepted Solution

    Imports System.IO

    Public Class FileOperations

      Public Sub RenameFilesInFolder(ByVal pathFolder As String, ByVal fileExtension As String)

        Dim dirInfo As DirectoryInfo = New DirectoryInfo(pathFolder)

        ' Loop through each of the files using the pattern *.jpg for example.
        For Each fileCurrent As FileInfo In dirInfo.GetFiles("*." & fileExtension)
          Rename(fileCurrent.Name, "Renamed-" & fileCurrent.Name)

      End Sub

    End Class

    LVL 3

    Author Comment

    Thanks Bob :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now