Solved

file copy with wildcard

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

Independent Software Vendors: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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