Small projects (C #)

zhaozj2021-02-16  49

app.cs

Using system; using system.io;

Namespace com.todayisp.bakup {///

/// App Abstract Description of the APP. /// public class app {// lists all directories under a disk, not including files. // Directory path PathStr, such as E: // Returns an array of directories. Public string [] Directorys (String pathstr) {if (pathstr == null) Return null; if (! Directory.exists (pathstr)) {Console.Writeline ("Error: FilePath Not Exist -" pathstr); Return Null Console.writeline; string [] filestrs = Directory.getdirector (pathStr); for (int i = 0; i

// 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 {///

/// Class1 Abstract Description. /// class class1 {/// /// The primary entry point of the application. /// [stathread] static void main (string [] args) {// // Todo: Add code to start the application // app App = New app ();

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 = convert.TOINT32 (MaxContent) Return; String DirName = DIR [i] .trim (); string RARPATH = DIRNAME ". RAR"; int pos = rarpath.lastindexof (@ "/"); string rarname = rarpath.substring (POS 1, RARPATH.LENGTH-POS-1); if (App.Readlog (LogPath, DIRNAME , BakupDay)) {BOOL BAKUP = App.bak (Rarpath, Dirname); Bool Bakup2 = app.writelog (LogPath, DateTime.today.toshortDateString () " RarName " DIRNAME.TOLOWER ()); Console. WriteLine ("Bakup" Dirname " RarName " Bakup ". Write to log" Bakup2); fileinfo fi = new fileinfo (RARPATH); Content = Content FI.LENGTH; console.writeline (Content "bytes ");} Else {console.writeline (" no need to bukup " dirname);}} catch (exception ex) {console.writeLine (ex.MESSAGE);}

}}}

//bakup.exe.config configuration file

- Application Specific Settings ->

转载请注明原文地址:https://www.9cbs.com/read-16263.html

New Post(0)