...

View Full Version : VB script- NEED HELP!



yuchen
09-12-2008, 02:26 PM
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


Wscript.Echo "Job Done"

oracleguy
09-12-2008, 05:39 PM
We aren't psychics, what was the error message you were getting?

Depending on the filesystem there might be some sort of limit on the depth of a directory tree.

yuchen
09-12-2008, 09:28 PM
the error msg was: line 20
char 5
file not found

oracleguy
09-12-2008, 10:03 PM
Is line 20:



b = b-1


or was it a different line?

yuchen
09-13-2008, 12:26 AM
yeah it was b=b-1...
you can test the script urself... just copy and paste it
thx for any help

yuchen
09-13-2008, 12:26 AM
it works when i creat like 50 folders but it doesnt work when i create too many

oracleguy
09-13-2008, 12:52 AM
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:


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.

yuchen
09-13-2008, 09:02 PM
is there anyway around this?

oracleguy
09-15-2008, 07:53 PM
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.

Gox
09-15-2008, 11:35 PM
Would this problem happen to have anything to do with the Maximum Length allowed for paths in Windows?


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.)

http://msdn.microsoft.com/en-us/library/aa365247.aspx

oracleguy
09-15-2008, 11:59 PM
Would this problem happen to have anything to do with the Maximum Length allowed for paths in Windows?



http://msdn.microsoft.com/en-us/library/aa365247.aspx
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum