Good morning,
I'm creating a small application as part of a learning project. I'm using Visual Express 2010 and the language is C#.
I've set up two folders (destinationFolder and sourceFolder). The first one contains the following files:
data1.txt, data2.txt, data3.txt, data4.txt
The second one contains the exact same files but with "v2" written inside them.
The application is supposed to take all text files in sourceFile and copy them overwriting the files found in the destinationFolder, so that they will have "v2" written inside too.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Updater
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("--- (!) APP UPDATER (!) ---");
Console.WriteLine("press enter to begin update");
Console.ReadLine();
string sourceFolder = "C:\\Users\\Desktop\\sourceFolder";
Console.WriteLine("--- updating --- beginning update");
string destinationFolder = AppDomain.CurrentDomain.BaseDirectory; // from where .exe is run
string[] allFilesInSourceFolder = System.IO.Directory.GetFiles(sourceFolder);
string[] allFilesInDestinationFolder = System.IO.Directory.GetFiles(destinationFolder);
Console.WriteLine("getting data from " + sourceFolder);
Console.WriteLine("beginning copy in " + destinationFolder);
Console.WriteLine("");
for (int i = 0; i < allFilesInSourceFolder.Length; i++)
{
System.IO.File.Copy(allFilesInSourceFolder[i], allFilesInDestinationFolder[i], true);
Console.WriteLine("--- (!) updating (!) --- copying file " + i + "/" + allFilesInSourceFolder.Length);
}
Console.WriteLine("");
Console.WriteLine("--- UPDATE FINISHED --- press enter to exit");
Console.ReadLine();
}
}
}
For some reason, only data1.txt and data2.txt get copied without problems. The rest is not copied. Also, why my loop never reaches 4/4?
This was strictly a security issue. It got resolved in the past by simply calling IT to have me added to some security group.