Solved

file copy with wildcard

Posted on 2006-10-23
3
417 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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