Solved

file copy with wildcard

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

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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