Solved

file copy with wildcard

Posted on 2006-10-23
3
395 Views
Last Modified: 2012-05-05
I am trying the following command but it is not working:

 
                        My.Computer.FileSystem.CopyFile(strcopyloc & strRadiapromote & "*", strcopydes)

How can I copy files using a wildcard?  Thanks, Chad
                   
0
Comment
Question by:chadmanvb
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 17793542
Hi chadmanvb;

The My.Computer.FileSystem.CopyFile only copies 1 file and does not use the wild card character. So to do what you want this is what you can do. The following code sample copies multiple files using wild card character.

Where:
    SourceDir     = Copy from directory
    DestDir        = Copy to directory
    FilePattern    = Files to be copyed can use wild card characters
    SubDir         = Also look in sub directory of source for files to copy
    Returns a 2 element array of integers index 0 number of files copyed
                and index 1 number of files that were not copied.

    Private Function CopyFiles(ByVal SourceDir As String, ByVal DestDir As String, _
        ByVal FilePattern As String, ByVal SubDir As Boolean) As Integer()

        Dim FileCount() As Integer = {0, 0}
        Dim sOption As Microsoft.VisualBasic.FileIO.SearchOption

        If SourceDir = "" Or Not Directory.Exists(SourceDir) Then FileCount(0) = -1
        If DestDir = "" Or Not Directory.Exists(DestDir) Then FileCount(1) = -1
        If FileCount(0) = -1 Or FileCount(1) = -1 Then Return FileCount
        If FilePattern = "" Then FilePattern = "*.*"
        If SubDir Then
            sOption = FileIO.SearchOption.SearchAllSubDirectories
        Else
            sOption = FileIO.SearchOption.SearchTopLevelOnly
        End If

        For Each FileCopy As String In My.Computer.FileSystem.GetFiles(SourceDir, _
            sOption, FilePattern)
            Dim FName As String = FileCopy.Substring(FileCopy.LastIndexOf("\"c))
            Try
                My.Computer.FileSystem.CopyFile(FileCopy, DestDir & FName)
                FileCount(0) += 1
            Catch ex As Exception
                FileCount(1) += 1
            End Try
        Next

        Return FileCount

    End Function

Fernando
0
 

Author Comment

by:chadmanvb
ID: 17806051
It worked perfect.  Thanks, Chad
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17806170
Not a problem, glad I was able to help. ;=)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

12 Experts available now in Live!

Get 1:1 Help Now