Copy Files to new folder

  • Thread starter Thread starter Pugita
  • Start date Start date
P

Pugita

Guest
How to copy .exe files to new folder, here the example: a folder have 10 files.. 3 of 10 files are .exe files, after click one button, only .exe files will be copied to another folder. Please help me, I'm using formApplication of Visual Basic.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string FROM_DIR = "C:/Users/Hamiroel Nazrin/Desktop/Home/A/B/";
string TO_DIR = "C:/Users/Hamiroel Nazrin/Desktop/Destination/";

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo diCopyForm = new DirectoryInfo(FROM_DIR);
FileInfo[] fiDiskfiles = diCopyForm.GetFiles();
foreach (FileInfo curFile in fiDiskfiles)
{
try
{
File.Copy(curFile.FullName, TO_DIR + curFile.Name);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

}
}
}

Continue reading...
 
Back
Top