using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ThumbnailImages
{
public partial class ImageList : Form
{
public ImageList()
{
InitializeComponent();
}
{
public partial class ImageList : Form
{
public ImageList()
{
InitializeComponent();
}
private static string _source, _target;
private void ImageList_Load(object sender, EventArgs e)
{ }
private void ImageList_Load(object sender, EventArgs e)
{ }
public void ListFiles(FileSystemInfo info)
{
if (!info.Exists) return;
{
if (!info.Exists) return;
DirectoryInfo dir = info as DirectoryInfo;
if (dir == null) return;
if (dir == null) return;
FileSystemInfo[] files = dir.GetFileSystemInfos();
for (int i = 0; i < files.Length; i++)
{
FileInfo file = files[i] as FileInfo;
if (file != null)
{
if (file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".jpg" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".JPG" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".bmp" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".BMP")
{
this.treeView1.Nodes.Add(file.FullName);
}
}
else
{
try
{
this.treeView1.Nodes.Add(dir.FullName);
ListFiles(files[i]);
}
catch (Exception)
{ }
}
}
}
for (int i = 0; i < files.Length; i++)
{
FileInfo file = files[i] as FileInfo;
if (file != null)
{
if (file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".jpg" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".JPG" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".bmp" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".BMP")
{
this.treeView1.Nodes.Add(file.FullName);
}
}
else
{
try
{
this.treeView1.Nodes.Add(dir.FullName);
ListFiles(files[i]);
}
catch (Exception)
{ }
}
}
}
public void ListFiles(FileSystemInfo info,bool flag)
{
if (!info.Exists) return;
{
if (!info.Exists) return;
DirectoryInfo dir = info as DirectoryInfo;
if (dir == null) return;
if (dir == null) return;
FileSystemInfo[] files = dir.GetFileSystemInfos();
for (int i = 0; i < files.Length; i++)
{
FileInfo file = files[i] as FileInfo;
if (file != null)
{
if (file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".jpg" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".JPG" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".bmp" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".BMP")
{
this.treeView2.Nodes.Add(file.FullName);
}
}
else
{
try
{
this.treeView2.Nodes.Add(dir.FullName);
ListFiles(files[i],false);
}
catch (Exception)
{ }
}
}
}
for (int i = 0; i < files.Length; i++)
{
FileInfo file = files[i] as FileInfo;
if (file != null)
{
if (file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".jpg" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".JPG" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".bmp" || file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".BMP")
{
this.treeView2.Nodes.Add(file.FullName);
}
}
else
{
try
{
this.treeView2.Nodes.Add(dir.FullName);
ListFiles(files[i],false);
}
catch (Exception)
{ }
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
ListFiles(new DirectoryInfo(this.folderBrowserDialog1.SelectedPath));
}
}
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
ListFiles(new DirectoryInfo(this.folderBrowserDialog1.SelectedPath));
}
}
private void button4_Click(object sender, EventArgs e)
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.txt_source.Text = this.folderBrowserDialog1.SelectedPath;
_source = this.folderBrowserDialog1.SelectedPath;
ListFiles(new DirectoryInfo(_source));
}
}
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.txt_source.Text = this.folderBrowserDialog1.SelectedPath;
_source = this.folderBrowserDialog1.SelectedPath;
ListFiles(new DirectoryInfo(_source));
}
}
private void button5_Click(object sender, EventArgs e)
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.txt_target.Text = this.folderBrowserDialog1.SelectedPath;
_target = this.folderBrowserDialog1.SelectedPath;
}
}
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.txt_target.Text = this.folderBrowserDialog1.SelectedPath;
_target = this.folderBrowserDialog1.SelectedPath;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (this.txt_source.Text.Trim() == "")
{
MessageBox.Show("请选择要复制的目标文件夹!");
return;
}
if (this.txt_target.Text.Trim() == "")
{
MessageBox.Show("请选择目的文件夹!");
return;
}
if (this.txt_source.Text == this.txt_target.Text)
{
MessageBox.Show("目标文件夹与目的文件夹不能相同");
}
CopyFiles(_source, _target);
ListFiles(new DirectoryInfo(_target),false);
}
{
if (this.txt_source.Text.Trim() == "")
{
MessageBox.Show("请选择要复制的目标文件夹!");
return;
}
if (this.txt_target.Text.Trim() == "")
{
MessageBox.Show("请选择目的文件夹!");
return;
}
if (this.txt_source.Text == this.txt_target.Text)
{
MessageBox.Show("目标文件夹与目的文件夹不能相同");
}
CopyFiles(_source, _target);
ListFiles(new DirectoryInfo(_target),false);
}
private void CopyFiles(string varFromDirectory, string varToDirectory)
{
Directory.CreateDirectory(varToDirectory);
{
Directory.CreateDirectory(varToDirectory);
if (!Directory.Exists(varFromDirectory)) return;
string[] directories = Directory.GetDirectories(varFromDirectory);
if (directories.Length > 0)
{
foreach (string d in directories)
{
CopyFiles(d, varToDirectory + d.Substring(d.LastIndexOf("\\")));
}
}
{
foreach (string d in directories)
{
CopyFiles(d, varToDirectory + d.Substring(d.LastIndexOf("\\")));
}
}
string[] files = Directory.GetFiles(varFromDirectory);
if (files.Length > 0)
{
foreach (string s in files)
{
File.Copy(s, varToDirectory + s.Substring(s.LastIndexOf(" \\")),true);
}
}
}
}
}
{
foreach (string s in files)
{
File.Copy(s, varToDirectory + s.Substring(s.LastIndexOf(" \\")),true);
}
}
}
}
}