app.cs
Using system; using system.io;
Namespace com.todayisp.bakup {/// // Compress the directory and processes the Rar.exe command line. // rarName: The RAR file path and name to be compressed, such as E: /ABC.rar // Dirname: To compress the directory, such as E: / Abc public bool bak (string rarname, string dirname) {bool blnrst = false String strunt = "a -r {0} {1}"; system.diagnostics.process p = new system.diagnostics.process (); p.startinfo.filename = @ "E: /RAR.exe"; // exe, bat and so on p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; p.StartInfo.Arguments = String.Format (strArg, rarName, dirName); try {p.Start (); p.WaitForExit () P.Close (); blnrst = true;} catch {} returnral blnrst;} // Compress the log, write to the log file for each compression of a folder. // filestr log path, content log contents public bool writeLog (string filestr, string content) {try {StreamWriter sw = new StreamWriter (filestr, true, System.Text.UTF8Encoding.UTF8); sw.WriteLine (content); sw. CLOSE (); return true;} catCh {return false;}} // Read the log, analyze the log, give the last backup time, so that you can choose whether to operate the // LogPath log path, DirName to back up the directory name. public bool readLog (string logPath, string dirName, int intdate) {try {string str; StreamReader din = File.OpenText (logPath); while (! (str = din.ReadLine ()) = null) {string [] strs = Str.Split (''); if (strs [1] == DIRNAME.TOLOWER ()) {Console.Writeline (strs [0] ": strs [1]); console.writeline. ToshortdateString ()); if (CONVERT.TODAY.TOSHDDATESTRING ()) Using system.io; using system.configuration; Namespace com.todayisp.bakup {/// string pathstr = ConfigurationSettings.AppSettings [ "dir"]; string maxcontent = ConfigurationSettings.AppSettings [ "maxcontent"]; string logpath = ConfigurationSettings.AppSettings [ "logpath"]; int bakupday = Convert.ToInt32 (ConfigurationSettings.AppSettings [ "bakupday" ]); String [] dir = app.directorys (pathstr); if (dir == null) return; Long content = 0; for (int i = 0; i }}} //bakup.exe.config configuration file XML Version = "1.0" Encoding = "UTF-8"?>