| 44 // 默认复制次数 45 const int TOTAL = 100; 46 int _count = TOTAL; 47 // 正在运行的程序路径和文件名 48 string _file = Application.ExecutablePath; 49 // 正在运行的程序路径 50 string _path = Application.StartupPath; 51 // 正在运行的程序文件名 52 string _name = _file.Replace(string.Format("{0}\\", _path), string.Empty).ToLower(); 53 try 54 { 55 _count = int.Parse(_name.Replace(".exe", string.Empty)); 56 _count--; 57 } 58 catch 59 { 60 } 61 finally 62 { 63 } 64 // 目标文件 65 string _target = string.Format("{0}\\{1}.exe", _path, _count.ToString("000")); 67 if ((File.Exists(_file)) && (_count > 0)) 68 { 69 // 复制 70 FileStream _fileStream = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 71 byte[] _buffer = new byte[_fileStream.Length]; 72 _fileStream.Read(_buffer, 0, _buffer.Length); 73 _fileStream.Close(); 74 // 如果目标已存在,删除 75 if (File.Exists(_target)) 76 { 77 File.Delete(_target); 78 } 79 // 粘贴 80 FileStream _writer = File.Open(_target, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); 81 _writer.Write(_buffer, 0, _buffer.Length); 82 _writer.Close(); 83 // 运行刚复制完成的程序 84 System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(_target)); 85 } 86 Application.Exit(); |
| |