从.NET有关文件路径的奇怪行为 [英] Strange behavior from .NET regarding file paths

查看:119
本文介绍了从.NET有关文件路径的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到通过教授谷歌这方面的消息,所以我在这里。以给定的路径名​​称,并将其粘贴到Windows资源管理器。在我的生成路径有一个额外的code发现错误后,我碰到这个偶然'。在目录前的路径名 \ 分离...

I couldn't find any information on this through professor Google, so here I am. Take the given path name and paste it into Windows Explorer. I stumbled across this after discovering bug in my code that generated the paths with an extra '.' in the path name before a directory \ separator...

@"C:\\pathto.\file.ext"

在code,.NET将调用时接受该路径 File.Create ,将生成的文件,但在这个路径:

In code, .NET will accept the path when calling File.Create and a file will be generated, but at this path:

@"C:\\pathto\file.ext"

复制 C:\\ pathto \ file.ext Windows资源管理器的地址栏,观看'。消失,带你到 C:\\ pathto \ file.ext

Copying C:\\pathto.\file.ext into Windows Explorer's address bar and watch the '.' disappear and take you to C:\\pathto\file.ext

它是用于.NET和Windows到它正常的行为不是导致一个问题,因为'。正在双方.NET和Windows的时候传递到文件操作删除。真正的问题是,在数据库中的所有文件名都以'\',而是存在于路径没有一个'\'......和 File.Exists()工作过,虽然路径是不是真正的物理位置...

Is it normal behavior for .NET and Windows to It's not causing an issue because the '.' is being removed by both .NET and Windows when passed into file operations. The real issue is that all the files in the DB have filenames with a '.\', but exists in paths that do not have a '.\'... and File.Exists() works too, although the path is not the 'real' physical location...

这是怎么回事吗?

推荐答案

这是Windows文件系统的一个功能。 MSDN

This is a "feature" of the Windows file system. MSDN:

不要结束一个文件或目录名用空格或句点。虽然底层的文件系统可以支持这样的名称,Windows外壳程序和用户界面没有。然而,这是可以接受的,以指定一个周期为名称的第一个字符。例如,.temp

Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, ".temp".

这篇关于从.NET有关文件路径的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆