この質問があります、
私の上司は、パスを入力できるプログラムを望んでいます.Console.ReadLine(directory);
これは無関係です. 私はこの部分を動かしました. 実際、コード/プログラム全体が正常に機能しています。パスのポイントは、プログラムが指定されたディレクトリ/サブディレクトリ内のすべてのファイルを最後の書き込み時間でスキャンすることです。彼はこれに最低限の労力を払いたいと思っています。そのため、Windows を使用してこのプログラムを 24 時間ごとに開始する計画です。この「最小限の労力」部分の唯一の問題は、開始時に毎回パスを入力する必要があることです。したがって、実際には自動的には進みません。
問題は、これを回避する方法はありますか? たとえばThread.Sleep();
、睡眠が終わったら、Console.ReadLine(directory);
?のすぐ下のラベルに移動します。
では、1 日 1 回ではなく、24 時間睡眠し、1 分間作業するのですか?
それが助けになるなら、ここにコードがあります:
using System.IO;
using System.Security.Permissions;
namespace CheckWithinTime
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Which folder do you wish to scan?");
string path = Console.ReadLine();
//copies everything from the console to a .txt file
FileStream filestream = new FileStream(@"C:\Logs\Log.txt", FileMode.Create);
var streamwriter = new StreamWriter(filestream);
streamwriter.AutoFlush = true;
Console.SetOut(streamwriter);
Console.SetError(streamwriter);
//this is the path which you type in a the beginning of the program
string[] files = Directory.GetFiles(path, "*.*", System.IO.SearchOption.AllDirectories);
List<string> updatedFiles = new List<string>();
DateTime from = DateTime.Now.AddDays(-1);
DateTime to = DateTime.Now;
foreach (string name in files)
{
FileInfo file = new FileInfo(name);
string fullname = file.FullName;
//checks if the last writed time occured less then 24 hours ago, if it's not it will not be loggeed
if (file.LastWriteTime >= from && file.LastWriteTime <= to)
{
updatedFiles.Add(name);
Console.WriteLine(file.FullName + " ; " + "last changed at >> " + " ; " + file.LastWriteTime.ToString());
//Console.WriteLine("File created at >> " + file.CreationTime.ToString());
//Console.WriteLine("File last opened at >> " + file.LastAccessTime.ToString());
Console.WriteLine();
}
}
streamwriter.Close();
filestream.Close();
//The mail class basicly sends an e-mail to the server with the log file, but this is irrelevant
Mail();
}
}
}
以前は単純なファイル システム ウォッチャーでした。その後は今のようになったのですが、そのConsole.ReadLine()
部分はありませんでした。そして今、彼は道を与えたいと思っています。
誰かが を回避する方法を教えてくれる場合はConsole.ReadLine()
、必要なときにのみ呼び出してください。私はそれをお願い申し上げます!
私の大きなテキストを前もって申し訳ありません。