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
|
/*
* Auteur : LhtlDrn
* Date : 06/07/2012
*
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
namespace Faultwin
{
/// <summary>
/// Copie un fichier de A vers B.
/// Renomme le fichier avec la date du jour (yyyyMMdd).
/// Change l'extension du fichier.
/// </summary>
class Program
{
static void Main(string[] args)
{
string sourcePath = ConfigurationManager.AppSettings["sourcePath"];
string targetPath = ConfigurationManager.AppSettings["targetPath"];
string sourceExtension = ConfigurationManager.AppSettings["sourceExtension"];
string targetExtension = ConfigurationManager.AppSettings["targetExtension"];
string dateToday = DateTime.Now.Date.ToString("yyyyMMdd");
// Liste tout les fichiers .txt du répertoire sourcePath
string[] sourceFileTab = Directory.GetFiles(sourcePath, sourceExtension);
foreach (string sSource in sourceFileTab)
{
try
{
string sTarget = Path.Combine(targetPath, Path.GetFileName(sSource));
// Copie le fichier de "sSource" vers "sTarget"
File.Copy(sSource, sTarget, true);
if (File.Exists(sTarget))
{
Console.WriteLine("{0} copied to {1}", sSource, sTarget);
}
// Renommer et change l'extension du fichier
File.Move(sTarget, Path.Combine(targetPath, dateToday + targetExtension));
if (File.Exists(Path.Combine(targetPath, dateToday + targetExtension)))
{
Console.WriteLine("{0} changed to {1}", sSource, Path.Combine(targetPath, dateToday + targetExtension));
}
// Supprime le fichier de "sSource"
File.Delete(sSource);
if (!File.Exists(sSource))
{
Console.WriteLine("{0} deleted", sSource);
}
}
catch (Exception ex)
{
Console.WriteLine("The process failed: {0}", ex.ToString());
}
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
} |
Partager