Solved

Copy Files that match a pattern

Posted on 2013-02-04
2
322 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

696 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