Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-12-2008, 01:26 PM   PM User | #1
yuchen
New to the CF scene

 
Join Date: Sep 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
yuchen is an unknown quantity at this point
VB script- NEED HELP!

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"
yuchen is offline   Reply With Quote
Old 09-12-2008, 04:39 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 09-12-2008, 08:28 PM   PM User | #3
yuchen
New to the CF scene

 
Join Date: Sep 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
yuchen is an unknown quantity at this point
the error msg was: line 20
char 5
file not found
yuchen is offline   Reply With Quote
Old 09-12-2008, 09:03 PM   PM User | #4
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Is line 20:

Code:
b = b-1
or was it a different line?
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 09-12-2008, 11:26 PM   PM User | #5
yuchen
New to the CF scene

 
Join Date: Sep 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
yuchen is an unknown quantity at this point
yeah it was b=b-1...
you can test the script urself... just copy and paste it
thx for any help
yuchen is offline   Reply With Quote
Old 09-12-2008, 11:26 PM   PM User | #6
yuchen
New to the CF scene

 
Join Date: Sep 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
yuchen is an unknown quantity at this point
it works when i creat like 50 folders but it doesnt work when i create too many
yuchen is offline   Reply With Quote
Old 09-12-2008, 11:52 PM   PM User | #7
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 09-13-2008, 08:02 PM   PM User | #8
yuchen
New to the CF scene

 
Join Date: Sep 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
yuchen is an unknown quantity at this point
is there anyway around this?
yuchen is offline   Reply With Quote
Old 09-15-2008, 06:53 PM   PM User | #9
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 09-15-2008, 10:35 PM   PM User | #10
Gox
Regular Coder

 
Gox's Avatar
 
Join Date: May 2006
Location: Ontario, Canada
Posts: 392
Thanks: 2
Thanked 20 Times in 20 Posts
Gox will become famous soon enough
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.)
http://msdn.microsoft.com/en-us/library/aa365247.aspx
Gox is offline   Reply With Quote
Old 09-15-2008, 10:59 PM   PM User | #11
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Quote:
Originally Posted by Gox View Post
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.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Reply

Bookmarks

Tags
folder, variable, vbs

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:05 PM.


Advertisement
Log in to turn off these ads.