创build绝对目录> 256个字符的文件夹树?

我有一个Excel VBAmacros,基于Excel文件创build一个文件夹树。

我目前的问题是,每当绝对目录变得非常长时,我似乎都会遇到错误。

该程序将抛出运行时错误76(未findpath)。 我有一种感觉,这是因为脚本引用超过256个字符的绝对path。

有没有解决这个问题? 或者是我唯一的select缩短文件夹名称,从而绝对pathstring?

编辑

我使用的代码如下:

Dim asheet As Range, r As Range, c As Range Dim fPath As String, tmp As String Set asheet = ActiveSheet.UsedRange For Each r In asheet.Rows fPath = DEST_FOLDER For Each c In r.Cells tmp = Trim(c.Value) If Len(tmp) = 0 Then Exit For Else tmp = Clean(tmp) fPath = fPath & tmp & "\" If Len(Dir(fPath, vbDirectory)) = 0 Then MkDir fPath End If Next c Next r 

Clean()是一个自定义函数,它将简单地从string中删除特殊字符,即!,#,_,@,$,&,*,^和%。

有没有另一种方法可以用来创build这些文件夹,可能会使用相对path而不是绝对path?

在某些情况下,Windows API的限制为260个字符 (C:\ + 256个字符+)。 如果你引用你以前的问题,你是否尝试过使用SHFileOperationW而不是SHFileOperationA