程序说已经制作了一个新目录,但在目标文件夹中不可见
我制作了一个简单的C#程序,该程序采用了目录的路径,如果该目录不存在,它将在给定的路径中创建它,但是当我转到应该创建它的路径时,没有显示目录。
using System;
using System.IO;
namespace Test
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo DIR = new DirectoryInfo(@"E:\A\B");
try
{
if(DIR.Exists)
{
Console.WriteLine("This folder already exists!");
}
else
{
DIR.Create();
Console.WriteLine("Folder created!");
}
}
catch(Exception ex)
{
Console.ForegroundColor = System.ConsoleColor.Red;
Console.WriteLine("Folder counldnt be created due to " + ex);
}
}
}
}
I made a simple c# program that takes a path of a directory, and if that directory doesn't exist, it creates it in the given path, but when I go to the path where it should have been created, no directory is shown.
using System;
using System.IO;
namespace Test
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo DIR = new DirectoryInfo(@"E:\A\B");
try
{
if(DIR.Exists)
{
Console.WriteLine("This folder already exists!");
}
else
{
DIR.Create();
Console.WriteLine("Folder created!");
}
}
catch(Exception ex)
{
Console.ForegroundColor = System.ConsoleColor.Red;
Console.WriteLine("Folder counldnt be created due to " + ex);
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的程序在第二次运行中告诉您,该文件夹已经存在,我认为您正在寻找错误的位置。您是否有多台计算机,或者这是在虚拟机中运行的,并且正在检查主机?还是只是您的探险家不刷新?
我刚刚添加了一行
system.diagnostics.process.start(dir.fullname);
在启动资源管理器并打开新创建的目录的程序中。如果那将失败,那么您应该将您的E:驱动器chkdsk chkdsk,也许有些东西破了。
If your program tells you on the second run that the folder already exists I assume you are looking in the wrong place. Do you have multiple computers or is this running in a virtual machine and you are checking on the host? Or is just your explorer not refreshing?
I just added one line
System.Diagnostics.Process.Start (DIR.FullName);
to your program that starts the explorer and opens the newly created directory.If even that will fail you should chkdsk your E: drive, perhaps there is something broken.