Solved

How to copy multiple files with same extension in .NET

Posted on 2003-10-27
3
935 Views
Last Modified: 2007-12-19
Hello,

In VB 6, I was able to copy all files from a folder with a .txt extension to a backup folder.  I used CopyFile and the *.txt to do it.  I do not believe you can use the wildcard symbol with the System.IO.File Copy member.

I'm sure there is a simple way to do this, but I have not discovered it.

smsak.
0
Comment
Question by:smsak
3 Comments
 
LVL 4

Accepted Solution

by:
NetPointer earned 50 total points
ID: 9630125
I use GetFiles method of Directory Object with wildcard, and loop thru it.

Regards.
NetPointer
0
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 50 total points
ID: 9633938
You can use wildcards

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim FilePath As String = "C:\temp\"

        Dim rFileName As String = ""
        Do
            If rFileName = "" Then
                'Call Dir with Path info
                rFileName = Dir(FilePath & "*.txt")
            Else
                rFileName = Dir()
            End If
            If rFileName = "" Then Exit Do
            File.Copy(FilePath & rFileName, DestinationPath)
        Loop

    End Sub
End Class
0
 

Author Comment

by:smsak
ID: 9634065
I thank you both for your input.

smsak.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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