Solved

How to copy multiple files with same extension in .NET

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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