난 파일을 검색이 기능을 가지고 :어떻게하면 파일 이름의 일부만 가져올 수 있습니까? 예를 들어
public void Search(string strExtension,
DirectoryInfo di,
List<FileSystemInfo> pResult)
{
try
{
foreach (FileInfo fi in di.GetFiles())
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => label2.Text = fi.Name));
}
if (fi.Name == "MessageLog.xsl")
{
foreach (FileInfo fii in di.GetFiles())
{
if (fii.Extension == strExtension)
pResult.Add(fii);
}
if (InvokeRequired)
{
BeginInvoke(new Action(() => label4.Text = pResult.Count.ToString() + Environment.NewLine));
}
}
}
foreach (DirectoryInfo diChild in di.GetDirectories())
Search(strExtension, diChild, pResult);
}
catch (Exception e)
{
}
}
검색이 작은 클래스 사용하여 메신저 이상 :
public class MyItem
{
public FileSystemInfo fsi { get; set; }
public override string ToString()
{
return this.fsi.Name;
}
}
그리고 파일 BackgroundWorker에 완료 이벤트에 표시 이름 :
를 :private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
for (int i = 0; i < this.fsi.Count; i++)
{
this.listBox1.Items.Add(new MyItem() { fsi = fsi[i] });
}
}
리스트 박스의 결과는 다음과 같이, 예를 들면
danny125645.xml
yaron576567.xml
이것은 디렉토리가없는 파일 이름입니다.
숫자가 없으므로 파일 이름을 구문 분석 할 수 있습니까?
danny.xml
yaron.xml
[문자열에서 숫자를 제거하는 방법 (http://stackoverflow.com/questions/1657282/how-to-remove- numbers-from-string-in-regex-replace) –