Directory.SetCurrentDirectory引发PathTooLongException [英] Directory.SetCurrentDirectory throws PathTooLongException

查看:130
本文介绍了Directory.SetCurrentDirectory引发PathTooLongException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于stackoverflow有几个相关的问题,但是要么我的情况有所不同,要么我太笨了以至于无法将它们与情况联系起来.我希望有人可以帮助我.此外,我什至不是.NET开发人员,所以对于任何错误的术语使用,我都深表歉意.

我的情况如下:用于部署.net应用程序(单击一次)的工具将其放在全名超过300个字符的目录中.该应用程序使用第三方组件(称为dbstore)来处理驻留在应用程序部署目录中的指定文件.

到目前为止,我们正在使用Assembly.GetExecutingAssembly().GetName().CodeBase构造要传递给dbstore的文件的标准名称.但是dbstore使用旧式API,并在尝试打开文件时失败.

由于预计dbstore不会很快更改,因此建议将应用程序chdir部署到部署目录,并将当前目录中的相对路径名传递给它.这也是接受的响应 C#代码中的PathTooLongException 中描述的方法

但是我发现Directory.SetCurrentDirectory也会抛出PathTooLongException.即使当我使用UNC路径名时也会发生这种情况,例如以\\?\0000000000000\...

开头的名称

我从根本上做错了吗?还有其他功能要使用吗?

看来没有办法实现我想要的东西.据我所知,没有办法将当前目录设置为长路径.

解决方案

使用Environment.SetCurrentDirectory()会得到类似的结果吗?

如果是这样,您可能要在子文件夹之后更改目录子文件夹.


Windows实际上为文件路径(WinXP)或260个字符(Vista)设置了255个字符的限制. 请注意,此限制不适用于文件系统,因此可以将文件存储在如此长的目录路径中,但是Windows资源管理器和许多Windows服务无法从该路径读取.

实际上,它似乎也包含.NET框架方法,因为您无法访问此类文件.您可能需要编写自己的文件系统API,但这有点过多的开销.您不能只是缩短文件路径吗? Windows是否提供一种简化的方式来寻址文件(例如8个八位字节的文件名)?

来源: http://labnol.blogspot.com/2006/10/limitations-with-long-file-names-on.html

There are several related questions on stackoverflow but either my situation is different or I am too dumb to relate those to situation. I am hoping someone can help me with this. Further I am not even much of a .NET developer so I apologize in advance for any wrong terminology use.

My scenario is as follows: The tool that is used to deploy our .net application (One Click?) puts it in a directory whose full name exceeds 300 characters. The application uses a third party component -- lets call it dbstore -- that processes the specified file that resides in the application deployment directory.

So far we were using Assembly.GetExecutingAssembly().GetName().CodeBase to construct the fully qualified name of the file to pass to dbstore. But dbstore uses old style APIs and fails when it tries to open the file.

Since dbstore is not expected to change soon, it was recommended that the application chdir to the deployment directory and pass a relative path name in current directory to it. This is also the approach described in the accepted response PathTooLongException in C# code

However I find that Directory.SetCurrentDirectory also throws PathTooLongException. This happens even when I am using UNC path name, e.g a name starting with \\?\0000000000000\...

Am I doing something fundamentally wrong? Is there another function to use?

EDIT: It seems there is no way to achieve what I am looking for. Far as I can tell there is no way to set current directory to a long path.

解决方案

Do you get a similar result when using Environment.SetCurrentDirectory() ?

If so, you may want to change your directory subfolder after subfolder.

EDIT:
Windows actually sets a limitation of 255 chars for a file path (WinXP) or 260 chars (Vista). Note that this limitation does not apply for the filesystem, so you can have a file stored in such a long directory path, but Windows Explorer and many Windows services cannot read from such path.

Actually it seems to also include .NET framework methods since you cannot access such files. You may need to write your own filesystem API, but that's a bit too much overhead. Can't you just shorten the file path ? Does Windows offer a shortened way to address a file (like 8 octet file names) ?

Source: http://labnol.blogspot.com/2006/10/limitations-with-long-file-names-on.html

这篇关于Directory.SetCurrentDirectory引发PathTooLongException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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