我在集成两段代码时遇到了一些麻烦。第一个检查文件的大小,下一个通过 SQL 数据库循环并查找文件的匹配名称。我基本上想检查它是否是一个新文件,或者自从我上次记录它的一些数据以来文件是否已更改。
这将获取目录中每个文件的大小
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("C:\\Users");
// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles();
// Display the names and sizes of the files.
MessageBox.Show("The directory {0} contains the following files:", di.Name);
foreach (FileInfo f in fiArr)
MessageBox.Show("The size of" + f.Name + " is " + f.Length + " bytes.");
这段代码循环直到找到一个马赫数或直到所有条目都被查看过。
try
{
// LINQ query for all files containing the word '.txt'.
var files = from file in
Directory.EnumerateFiles("C:\\Users")
where file.ToLower().Contains(".txt")
select file;
foreach (var file in files)
{
//Get path to HH file
filename = System.IO.Path.GetFileName(file);
tempString = "";
//Keep looking trough database utill database empty or HH found
while (inc != numberOfSessions && (filename != tempString))
{
sessionRow = sessions.Tables["Sessions"].Rows[inc];
tempString = sessionRow.ItemArray.GetValue(1).ToString();
inc++;
}
假设 ItemAttay.GetValue(2) 返回文件的保存大小。如果我怎样才能最有效地保持while循环
inc != numberOfSessions && (filename != tempString) && (sessionRow.ItemArray.GetValue(2) == f.length)
感谢您的关注!