Solved

Copy Files that match a pattern

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading the web config for a running service on Windows 10 16 48
Sub or Function is not defined 6 43
SQL Query Help Top 1 and Distinct? 6 35
VS 2017 18 30
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

792 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