Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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"

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the error msg was: line 20
    char 5
    file not found

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Is line 20:

    Code:
    b = b-1
    or was it a different line?
    OracleGuy

  • #5
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah it was b=b-1...
    you can test the script urself... just copy and paste it
    thx for any help

  • #6
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it works when i creat like 50 folders but it doesnt work when i create too many

  • #7
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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

  • #8
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is there anyway around this?

  • #9
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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

  • #10
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    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

  • #11
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •