?
Solved

file copy with wildcard

Posted on 2006-10-23
3
Medium Priority
?
449 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
[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
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 1000 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 63

Expert Comment

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

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

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