Solved

Copy Files that match a pattern

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

20 Experts available now in Live!

Get 1:1 Help Now