vb6.0 路径长度限制问题
近日在做一程序,在测试创建多级目录时,发现总有最底几级不能创建,几经测试发现目录是受绝对路径不能创建超过255个字符,超过了这个长度就不能创建了
创建使用的vb6.0的 mkdir
后来又测试使用wscript.shell对象和scripting.filesystemobject对象创建,均存在这个问题
后来在dos cmd环境中创建,发现也存在此问题
我的系统是winxp sp3
请教大家 有没有能超过255个字符限制的方法?
[解决办法]
面前明摆着是一堵墙,还硬要往上面撞,何苦呢。
干吗要创建那么多层的文件夹,又要把名字弄得那么长呢……
你难道就没想过用其它方式‘组织’一下么。
[解决办法]
印象中记得是创建好了再移动进去是可以的。
不过要想读取文件,还得移动出来。
[解决办法]
CreateFile
The CreateFile function creates or opens the following objects and returns a handle that can be used to access the object:
files
pipes
mailslots
communications resources
disk devices (Windows NT only)
consoles
directories (open only)
HANDLE CreateFile(
LPCTSTR lpFileName, // pointer to name of the file
DWORD dwDesiredAccess, // access (read-write) mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// pointer to security attributes
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to file with attributes to
// copy
);
Parameters
lpFileName
Pointer to a null-terminated string that specifies the name of the object (file, pipe, mailslot, communications resource, disk device, console, or directory) to create or open.
If *lpFileName is a path, there is a default string size limit of MAX_PATH characters. This limit is related to how the CreateFile function parses paths.
Windows NT: You can use paths longer than MAX_PATH characters by calling the wide (W) version of CreateFile and prepending "\\?" to the path. The "\\?" tells the function to turn off path parsing. This lets you use paths that are nearly 32,000 Unicode characters long. However, each component in the path cannot be more than MAX_PATH characters long. You must use fully-qualified paths with this technique. This also works with UNC names. The "\\?" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\tom_1\hotstuff\coolapps" is seen as "\\tom_1\hotstuff\coolapps".
dwDesiredAccess
[解决办法]
哈哈,这下知道为什么以前的“C:\Documents and Settings”后来变成了"C:\Users"了吧