Simple question....moving files that start with a certain name

Posted on 2007-07-30
Last Modified: 2010-04-23
I have a directory that contains about 100 files.  Every day new files are going to be moved there for me and I would like to have a program that moves them into a folder.  The files will all start with "Finance".  They will be placed in the directory "L:\" and I would like to move them to  "L:\Finance".


Question by:collages
    LVL 96

    Accepted Solution

    Try something like this:

    Imports System.IO

    Public Class FileMover

      Public Shared Sub MoveFiles(ByVal sourceFolder As String, ByVal targetFolder As String, ByVal pattern As String)

        Dim directory As New DirectoryInfo(sourceFolder)

        For Each file As FileInfo In directory.GetFiles(pattern)
          Dim destFileName As String = Path.Combine(targetFolder, Path.GetFileName(file.FullName))
        Next file

      End Sub

    End Class

       FileMover.MoveFiles("L:\", "L:\Finance", "Finance*.*")

    LVL 1

    Author Comment

    Thats perfect, thanks a ton!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now