두 개의 코드를 통합하는 데 문제가 있습니다. 첫 번째 파일의 크기를 확인하고 다음 하나는 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)는 저장된 파일 크기를 반환합니다. 어떻게 가장 효율적으로
경우 INC가는 while 루프를 유지할 수 있습니다! = numberOfSessions & & (파일 이름을! = tempString) & & (sessionRow.ItemArray.GetValue (2) == f.length)감사에 대한 봐라!
파일 내용이 변경되었지만 크기가 동일해도 상관 없습니까? 그렇다면 "파일 크기가 변경되었는지 확인"기준이 작동하지 않습니다. 대신 해시를 계산할 수 있습니까? –
새 파일인지 또는 파일에 추가 된 파일인지 알기가 어렵습니다. 절대 (결코) 나는 더 작아 질 것입니다. 해시 계산 방법에 대해 어떻게 생각하십니까? –
기본 .NET 해시 함수의 기본 클래스는 [HashAlgorithm]입니다 (http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx). http://support.microsoft.com/kb/307020에서 컴퓨팅 파일 해시를 설명하는 몇 가지 정말 오래된 설명서가 있습니다. –