-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm2.cs
90 lines (79 loc) · 2.5 KB
/
Form2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
namespace HyperlinkExtract
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories);
listBox1.Items.AddRange(files
.Select(f => new ListItem
{
Display = Path.GetFileName(f),
Path = f
})
.ToArray());
}
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
int index = listBox1.IndexFromPoint(e.X, e.Y);
if (index >= 0)
{
listBox1.SelectedIndex = index;
}
}
}
private void selectToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex >= 0)
{
textBox1.Text = listBox1.Items[listBox1.SelectedIndex].ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
ListItem[] list = listBox1.Items.OfType<ListItem>().ToArray();
listBox1.Items.Clear();
if (textBox1.Text == string.Empty)
{
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories);
listBox1.Items.AddRange(files
.Select(f => new ListItem
{
Display = Path.GetFileName(f),
Path = f
})
.ToArray());
}
else
{
Regex regex = new Regex(textBox1.Text);
foreach (ListItem item in list)
{
if (regex.IsMatch(item.Display))
{
listBox1.Items.Add(item);
}
}
}
}
}
}