P
Pugita
Guest
Hello Everyone,
One Question about coding (Visual Studio C# WindowsformApplication)
In "Source" folder have random folders such as "20190401", "20190402", "20190403", "20180401", "20170401" and "20160401". Every of these folders have [10] text files.
What is the coding if I only want to copy all "201904**" folders with [3] text files inside it to "Target" folder? Which mean I only copy all folders StartWith "201904**" with [3] text files from "Source" folder to "target" folder after I click a button. Here is my coding for now.
Code:
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
string FROM_DIR = "C:/Users/5004117928/Desktop/Source";
string TO_DIR = "C:/Users/5004117928/Desktop/Target/";
string filename = "t";
public Form1()
{
InitializeComponent();
}
private void button_Click(object sender, EventArgs e)
{
DirectoryInfo diCopyForm = new DirectoryInfo(FROM_DIR);
FileInfo[] fiDiskfiles = diCopyForm.GetFiles();
foreach (FileInfo newfile in fiDiskfiles.Take(3))
{
try
{
if (newfile.Name.StartsWith(filename))
{
File.Copy(newfile.FullName, TO_DIR + newfile.Name);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
Best Regard,
Pugita
Continue reading...
One Question about coding (Visual Studio C# WindowsformApplication)
In "Source" folder have random folders such as "20190401", "20190402", "20190403", "20180401", "20170401" and "20160401". Every of these folders have [10] text files.
What is the coding if I only want to copy all "201904**" folders with [3] text files inside it to "Target" folder? Which mean I only copy all folders StartWith "201904**" with [3] text files from "Source" folder to "target" folder after I click a button. Here is my coding for now.
Code:
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
string FROM_DIR = "C:/Users/5004117928/Desktop/Source";
string TO_DIR = "C:/Users/5004117928/Desktop/Target/";
string filename = "t";
public Form1()
{
InitializeComponent();
}
private void button_Click(object sender, EventArgs e)
{
DirectoryInfo diCopyForm = new DirectoryInfo(FROM_DIR);
FileInfo[] fiDiskfiles = diCopyForm.GetFiles();
foreach (FileInfo newfile in fiDiskfiles.Take(3))
{
try
{
if (newfile.Name.StartsWith(filename))
{
File.Copy(newfile.FullName, TO_DIR + newfile.Name);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
Best Regard,
Pugita
Continue reading...