我在外部驱动器出现故障时非常幸运,并且在很多情况下几乎失去了一切。最后,我有了创建一个控制台应用程序的想法,该应用程序可以自动“突袭”我的两个驱动器。现在就获取目录信息而言,我得到了它。出于某种原因,尽管当我尝试从一个复制到另一个时,它说访问被拒绝?有任何想法吗?这是我到目前为止所做的。(我只是先做我的电影和电视测试)
错误是“未经授权的访问例外:访问路径 'D:\External Backup\Movies and TV\Alien Quadrilogy' 被拒绝。”
string _movieDIR = @"D:\External Backup\Movies and TV";
string _movieDIR2 = @"G:\TEMP";
string[] movies = Directory.GetDirectories(_movieDIR);
foreach(string movie in movies)
{
File.Copy(movie, _movieDIR2);
}
Console.ReadLine();
更新完成的代码
string _movieDIR = @"D:\External Backup\Movies and TV";
string _movieDIR2 = @"G:\Movies and TV";
string[] movies = Directory.GetDirectories(_movieDIR);
if(Directory.Exists(@"G:\Movies and TV")){
Console.WriteLine("Purging old Movies Folder in G:");
Directory.Delete(@"G:\Movies and TV",true);
}
Console.WriteLine("Creating New Movies Folder in G:");
Directory.CreateDirectory(@"G:\Movies and TV");
double size = movies.Length;
double percent = 0.00;
double counter = 0;
foreach(string movie in movies)
{
Console.Write("\n\nCopying " + movie.ToString());
int pos = movie.IndexOf(@"V\");
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(movie, _movieDIR2+ @"\" + movie.Substring(pos+2).ToString(),true);
counter++;
percent = (counter / size)*100;
percent = Math.Round(percent,2);
Console.WriteLine("\n\nPercent Copied " + percent + "%\n\n");
}
Console.ReadLine();