i had an assignment in which you had to create a program that generates 50 subfolders, though the program i made could do that, it couldnt generate over 100 folders. Im just curious. is the file extension too long? and how do i solve this? Script is below...
Dim strfolder, b, sub1
Dim strRoot2, root
strRoot="c:\Users\Admin\Desktop"
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(strRoot)
Set colFolders=objFolder.SubFolders
strFolder = InputBox("Please Enter a Folder Name.")
b = InputBox("Please Enter How Many SubFolders")
If objFSO.FolderExists(strRoot & strFolder) Then
WScript.Echo "Folder " & strRoot & strFolder &_
" already exists"
Else
End If
Do while b>0
colfolders.Add strFolder
b = b-1
strRoot=strRoot&"\"&strfolder
Set objFolder=objFSO.GetFolder(strRoot)
Set colFolders=objFolder.SubFolders
Loop
There doesn't seem to be anything wrong with your program that I could see off hand however the real line that it is crashing on is this:
Code:
colfolders.Add strFolder
It seems to fail depending on the length of the directory you give it. When I gave it the directory name "saodjaodjaojdoajdoiajdaodijaodja" it only did 8. It seems after some debugging that once strRoot gets to 255 characters it goes awry.
It isn't clear why it is even happening, strings in VB should be able to handle much longer data than just 255 characters. I'm not sure what is causing that to crash.
Would this problem happen to have anything to do with the Maximum Length allowed for paths in Windows?
Quote:
Maximum Path Length
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\<some 256 character path string><NUL>" where "<NUL>" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)
Yes it would thank you. I was trying to find that information out originally as I suspected that to be the source of the problem but must have not used the right search terms. Thanks for posting that.
So my original theory has been validated the reason your program crashes is that the maximum length of a path in the file system is limited.