我正在从两个不同的文件夹中弹出文件并根据文件名进行排序。但我无法从一个指定的文件夹填充。为什么会那样。我想我正在做一些错误。请帮帮我。
我的代码段:
private void Form1_Load(object sender, EventArgs e)
{
//Initialize Directory path
string draft = ini.ReadValue("Location", "Draft");
string release = ini.ReadValue("Location", "Release");
string drawing = ini.ReadValue("Location", "Drawing");//<<-- Unable to populate this location to the gridview.. Its taking the files from above location..
string[] arrDraft = Directory.GetFiles(draft, "*", SearchOption.AllDirectories);
string[] arrRelease = Directory.GetFiles(release, "*", SearchOption.AllDirectories);
string[] arrDrawing = Directory.GetFiles(release, "*", SearchOption.AllDirectories);
dt.Columns.Add("Part Number");
dt.Columns.Add("Drawing");
dt.Columns.Add("Draft Path");
dt.Columns.Add("Release Path");
dt.Columns.Add("Comment");
dt.Columns.Add("Error");
List<FileDetails> lst = new List<FileDetails>();
foreach (string file in arrDraft)
{
Finder finder = new Finder(Path.GetFileName(file).Substring(0, 7));
string abc = Array.Find(arrRelease, finder.Match);
string def = Array.Find(arrDrawing, finder.Match);//<<--- Here is the mistake i guess i am doing
dt.Rows.Add(Path.GetFileName(file), def, file, abc, String.Empty, String.Empty);
}
dataGridView1.DataSource = dt;
}
// Search predicate returns true if a string ends in "saurus".
private static bool MatchFileName(String s, String _match)
{
return ((s.Length > 5) && (s.Substring(0, 7).ToLower() == _match.ToLower()));
}
public class FileDetails
{
public string FileName;
public string Drawing;
public string FilePathDraft;
public string FilePathRelease;
public string Comment;
public string ErrorMsg;
}
public sealed class Finder
{
private readonly string _match;
public Finder(string match)
{
_match = match.ToLower();
}
public bool Match(string s)
{
string fileName = s.Substring(s.LastIndexOf("\\") + 1);
return ((fileName.Length > 5) && (fileName.Substring(0, 7).ToLower() == _match));
}
答案 0 :(得分:1)
也许这一行
string[] arrDrawing = Directory.GetFiles(release, "*", SearchOption.AllDirectories);
应该是
string[] arrDrawing = Directory.GetFiles(drawing, "*", SearchOption.AllDirectories);
答案 1 :(得分:1)
应该是string name
drawing
。你已经给出了realease
这就是为什么它显示的原因。
请用
替换图纸代码 string[] arrDrawing = Directory.GetFiles(drawing, "*", SearchOption.AllDirectories);
全部设定...... !!!