?
Solved

Copy Files that match a pattern

Posted on 2013-02-04
2
Medium Priority
?
326 Views
Last Modified: 2013-02-04
I have two files that are being copied to a folder. One file name contains the word "email" and the other "ftp". I am trying to figure out how to take all the items that contan "ftp" and move them to another drive. Does anyone have a good idea how to accomplish?
0
Comment
Question by:earngreen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 2000 total points
ID: 38851594
You basically want to get all the files in the folder and then for each of them, check if they match a pattern.

    Dim strFileSize As String = ""
    Dim di As New IO.DirectoryInfo("C:\temp")
    Dim aryFi As IO.FileInfo() = di.GetFiles("*.txt")
    Dim fi As IO.FileInfo

    For Each fi In aryFi
        If(fi.Name.Contains("email")) Then
           // do something
        Else If (fi.Name.Contains("ftp")) Then
           // do something else
    Next

Reference:

http://www.thescarms.com/dotnet/ListFiles.aspx

Arun
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38851601
One line of code:

Directory.GetFiles("your-directory", "*ftp*", SearchOption.AllDirectories);

Open in new window

If u dont want to sesrch in sub directories remove the last parameter
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

764 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