Список результатов все пути
Привет
Моя проблема заключается в том что когда я нажимаю кнопку программа ищет в папке файлы с расширением gz и результат помещается в список с форматом C:\Program файлы\новые Folder\Compressed.gz.
Я хочу, чтобы результат в ListBox был обрезан с помощью этого формата New Folder\Compressed.gr
Что я уже пробовал:
<pre>using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; namespace SD { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string fileName; private void Form1_Load(object sender, EventArgs e) { //List<string> filenames = FindFiles(path.Text, exten.Text, check.Checked); //lstFiles.Items.Clear(); //foreach (string filename in filenames) //{ // lstFiles.Items.Add(filename); //} this.KeyPreview = true; } private void button1_Click(object sender, EventArgs e) { List<string> filenames = FindFiles(path.Text, exten.Text, check.Checked); lstFiles.Items.Clear(); foreach (string filename in filenames) { lstFiles.Items.Add(filename); } } private List<string> FindFiles(string dir_name, string patterns, bool search_subdirectories) { List<string> files = new List<string>(); string[] pattern_array = patterns.Split(';'); SearchOption search_option = SearchOption.AllDirectories; foreach (string pattern in pattern_array) { foreach (string filename in Directory.GetFiles(dir_name, pattern, search_option)) { if (!files.Contains(filename)) files.Add(filename); } } label1.Text = files.Count.ToString(); files.Sort(); return files; } private void lstFiles_SelectedIndexChanged(object sender, EventArgs e) { } private byte[] DecompressArray(byte[] content) { byte[] array; int num; using (MemoryStream memoryStream = new MemoryStream()) { using (MemoryStream memoryStream1 = new MemoryStream(content)) { using (GZipStream gZipStream = new GZipStream(memoryStream1, CompressionMode.Decompress)) { byte[] numArray = new byte[1024]; do { num = gZipStream.Read(numArray, 0, (int)numArray.Length); memoryStream.Write(numArray, 0, num); } while (num > 0); } } array = memoryStream.ToArray(); } return array; } private void UnzipDirectory(byte[] compressed, string outputPath) { IEnumerator enumerator = null; IEnumerator enumerator1 = null; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } byte[] numArray = this.DecompressArray(compressed); XmlDocument xmlDocument = new XmlDocument(); using (MemoryStream memoryStream = new MemoryStream(numArray)) { xmlDocument.Load(memoryStream); XmlNode firstChild = xmlDocument.FirstChild; XmlNode xmlNodes = firstChild.FirstChild; XmlNode nextSibling = firstChild.FirstChild.NextSibling; try { enumerator = xmlNodes.ChildNodes.GetEnumerator(); while (enumerator.MoveNext()) { object objectValue = RuntimeHelpers.GetObjectValue(enumerator.Current); Directory.CreateDirectory(Path.Combine(outputPath, ((XmlNode)objectValue).Attributes.Item(0).Value)); } } finally { if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } try { enumerator1 = nextSibling.ChildNodes.GetEnumerator(); while (enumerator1.MoveNext()) { object obj = RuntimeHelpers.GetObjectValue(enumerator1.Current); string str = Path.Combine(outputPath, ((XmlNode)obj).Attributes.Item(0).Value); byte[] numArray1 = Convert.FromBase64String(((XmlNode)obj).InnerText); File.WriteAllBytes(str, numArray1); } } finally { if (enumerator1 is IDisposable) { (enumerator1 as IDisposable).Dispose(); } } } } private void lstFiles_DoubleClick(object sender, EventArgs e) { if (lstFiles.SelectedItem != null) { fileName = lstFiles.SelectedItem.ToString(); FileInfo fileInfo = new FileInfo(fileName); try { if (File.Exists(fileName)) { UnzipDirectory(File.ReadAllBytes(fileName), fileInfo.DirectoryName); File.Delete(fileName); } } catch (Exception exception) { ProjectData.SetProjectError(exception); Interaction.MsgBox("ERROR Please run program as Administrator", MsgBoxStyle.Critical, null); ProjectData.ClearProjectError(); return; } Interaction.MsgBox("Task Complete", MsgBoxStyle.Information, null); button1.PerformClick(); } } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.Control == true && e.KeyCode == Keys.S) { path.Visible = true; } if (e.Control == true && e.KeyCode == Keys.W) { path.Visible = false; } } } }