我在这里有点挑战。我应该备份一台计算机,因此我想使用 c:\ 作为我的 origo 来递归搜索要备份的文件。
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);
}
}
}
}
我从控制台(以管理员身份)运行程序。我收到此异常:异常:System.UnauthorizedAccessException:对路径“C:\Documents and Settings”的访问被拒绝。ved System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) ved System.IO.FileSystemEnumerableIterator 1.AddSearchableDirsToStack(SearchData localSearchData)
ved System.IO.FileSystemEnumerableIterator
1.MoveNext() ved System.Collections.Generic.List 1..ctor(IEnumerable
1 集合) ved System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption) ved Program.Main()
我也试过:net user administrator /active:yes
我需要访问根目录。谁能帮我?