【发布时间】:2016-02-16 08:48:39
【问题描述】:
我想问一个关于我在 c# 中的代码的简单问题 .... 我知道有很多主题具有相同或相似的主题/代码结果。但是我需要将我的代码交给学校,所以我不能只使用 Stackoverflow 或其他页面上的最佳解决方案。我向老师展示了我的代码,现在需要修复一个小错误。
代码是关于使用控制台报告备份文件的,因此在第一步中我检查文件夹是否存在。第二步是报告文件夹存在或不存在,如果不存在,代码会创建此文件夹并重新检查...
SITUATION : CONSOLE REPORT
folders doesnt exist:
02:02:06 directory for backup Exist ... can continue
02:02:05 directory for backup DOESNT EXIST ... creating required folders...
folders exist :
02:02:55 directory for backup Exist ... can continue
02:02:54 directory for backup Exist ... can continue
在第一个示例中,报告正常,但在第二个示例中,我的代码两次告诉我相同的信息...我只是无法让我的代码正常工作..
这是我的代码:
public void checkbackupfolders() {
do {
create_backup_folders();
} while (create_backup_folders() == false);
}
public bool create_backup_folders()
{
string path = "\\BACKUP\\" + Globals.hostname;
if (Directory.Exists(path))
{
consolecho("directory for backup Exist ... can continue");
return true;
}
else
{
consolecho("directory for backup DOESNT EXIST ... creating required folders...");
Directory.CreateDirectory("\\BACKUP\\" + Globals.hostname);
return false;
}
}
【问题讨论】:
标签: c# while-loop backup directory file-exists