Im having a bit of a challenge here. Im supposed to backup a computer, and therefore I would like to use c:\ as my origo for a recursive search for files to backup.
using System;
using System.IO;
class Program
{
static void Main()
{
int i;
string source = @"c:\";
string destin = @"x:\";
string[] TypeOfFiles = new string[14];
i=0;
// Images / Movies:
TypeOfFiles[i] = "jpg"; i++;
TypeOfFiles[i] = "gif"; i++;
TypeOfFiles[i] = "png"; i++;
TypeOfFiles[i] = "jpeg"; i++;
TypeOfFiles[i] = "tif"; i++;
TypeOfFiles[i] = "tiff"; i++;
TypeOfFiles[i] = "bmp"; i++;
// Adobe
TypeOfFiles[i] = "pdf"; i++;
// Office Classic:
TypeOfFiles[i] = "doc"; i++;
TypeOfFiles[i] = "xls"; i++;
TypeOfFiles[i] = "mdb"; i++;
// Office New:
TypeOfFiles[i] = "docx"; i++;
TypeOfFiles[i] = "xlsx"; i++;
TypeOfFiles[i] = "mdbx"; i++;
for (int n = 0; n <= TypeOfFiles.GetUpperBound(0); n++)
{
string[] files = Directory.GetFiles("C:\\", "*." + TypeOfFiles[n], SearchOption.AllDirectories);
foreach (string file in files)
{
Console.WriteLine(file);
}
}
}
}
Im running the program from a console (as Administrator).
I get this exception:
Exception: System.UnauthorizedAccessException: Access to path 'C:\Documents and Settings' was denied.
ved System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
ved System.IO.FileSystemEnumerableIterator1.AddSearchableDirsToStack(SearchData localSearchData)
ved System.IO.FileSystemEnumerableIterator
1.MoveNext()
ved System.Collections.Generic.List1..ctor(IEnumerable
1 collection)
ved System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
ved Program.Main()
I have also tried: net user administrator /active:yes
I need to access the root. Can anyone help me?