相关疑难解决方法(0)

如何删除目录中的所有文件和文件夹?

使用C#,如何从目录中删除所有文件和文件夹,但仍保留根目录?

.net c#

621
推荐指数
16
解决办法
60万
查看次数

FileInfo.MoveTo()vs File.Move()

这两种移动文件的方法有什么区别吗?

System.IO.FileInfo f = new System.IO.FileInfo(@"c:\foo.txt");
f.MoveTo(@"c:\bar.txt");

//vs

System.IO.File.Move(@"c:\foo.txt", @"c:\bar.txt");
Run Code Online (Sandbox Code Playgroud)

.net c# file-io

24
推荐指数
3
解决办法
3万
查看次数

File.Exists("")和FileInfo之间存在什么区别

我在\ ProgramFiles(x86)\ MyAppFolder中有一个*.exe文件.

在x86应用程序中,我检查文件是否存在(64位系统).简单:

bool fileExists = File.Exists(@"\ProgramFiles(x86)\MyAppFolder\Manager.exe");
Run Code Online (Sandbox Code Playgroud)

结果是:"fileExists == false"(文件确实存在).据我所知,这是虚拟化.这里描述的问题很好.但下一个代码:

bool fileExists = new FileInfo("\\Path").Exists;
Run Code Online (Sandbox Code Playgroud)

"fileExists == true"

为什么在第一和第二种情况下结果不同?

var controller = new ServiceController(Product.ServiceName);
_manager.Enabled = controller.Status == ServiceControllerStatus.Running;

var info = new DirectoryInfo(Assembly.GetExecutingAssembly().Location);

var s = File.Exists(@"D:\TFS\GL_SOURCES\Teklynx_LPM\Dev\Server\Debug\Manager.exe");

string pathToManager = string.Empty;

if (info.Parent != null)
{
    var pathToModule = info.Parent.FullName;
    pathToManager = Path.Combine(pathToModule,"Manager.exe").Replace(" ",string.Empty);
}
Run Code Online (Sandbox Code Playgroud)

//效果很好

var fileInfo = new FileInfo(pathToManager);
var managerSeparator = new ToolStripSeparator()
{
    Visible = _manager.Visible = fileInfo.Exists // true
};
Run Code Online (Sandbox Code Playgroud)

//不起作用 …

.net c# virtualization

12
推荐指数
2
解决办法
8661
查看次数

即使文件为EXISTS,C#在`File.Exists`处的结果为FALSE

正如标题所说,我不知道我的代码有什么问题,但if (File.Exists)即使文件存在,也会给出否定结果.

以下是我的代码

if (File.Exists(ZFileConfig.FileName.Replace(".xml", "_abc.xml")))
Run Code Online (Sandbox Code Playgroud)

在这里,ZFileConfig.FileNameE:\\Application\\Application\\bin\\Debug\\resources\\FirstFile.xml

令人惊讶的是,这就是ZFileConfig.FileName.Replace(".xml", "_abc.xml")E:\\Application\\Application\\bin\\Debug\\resources\\FirstFile_abc.xml所需要的.EVENTHOUGH IF被罚下来返回TRUE.

在此输入图像描述

在此输入图像描述

.net c# winforms

5
推荐指数
1
解决办法
3000
查看次数

System.IO.File和System.IO.FileInfo之间有什么区别

为什么有两个类用于几乎相同的目的System.IO.File和System.IO.FileInfo.

c#

1
推荐指数
2
解决办法
898
查看次数

标签 统计

c# ×5

.net ×4

file-io ×1

virtualization ×1

winforms ×1