Solved

How to copy multiple files with same extension in .NET

Posted on 2003-10-27
3
939 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

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

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…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…

860 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