0
For i = 1 To 40 Step 1

  ChildFolderPath = ChildFolderPath & "\" & "LargeFolder" & i
  If fso.FolderExists(ChildFolderPath) Then
    MsgBox ("Folder Exists")
  else
    fso.CreateFolder (ChildFolderPath)
  End If
Next

But after creating 21 folders, I am getting error 53, "File path not found". Why?

5
  • 1
    What does ChildFolderPath contain initially? And could it be you are reaching the length limit for paths? I mean: ChildFolderPath gets "\LargeFolder<n>" appended all the time, that will safely reach the length limit at some point in time, guaranteed. Depending on what file system you use, it might be as low as 128. Commented Sep 30, 2013 at 12:28
  • 1
    ChildFolder has the path of a folder on the desktop.And yes..I want to add folders inside folders,so that the file name of the files in last folder,becomes greater than 255. Commented Sep 30, 2013 at 12:38
  • Unless the OP can provide a real good explanation why he needs to "mess things up" I suggest we don't promote script kiddy behavior. Commented Sep 30, 2013 at 17:05
  • I need this to make some testdata,which is required to test our application. Commented Oct 1, 2013 at 5:42
  • Why is it required? When asked to give a real good explanation, a "because it is required" reply is not exactly what Ansgar had in mind. Commented Oct 1, 2013 at 11:29

1 Answer 1

3

You're hitting the Windows limitation on maximum path length, which is 260 characters.

The linked article also mentions a workaround to use extended-length paths up to (approximately) 32767 characters long – add \\?\ before the drive name. For example:

ChildFolderPath = "\\?\C:\MyFolder"

As also noted in that article, even though you can create extended-length paths programmatically, the Windows shell (e.g. Explorer) may be unable to handle them properly. For example, you may get the "The source file name(s) are larger than is supported by the file system" error when trying to delete a long path folder from Explorer or the command prompt.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes,I used this "\\?\" and was able to create the folders,but now I want to have some files in that last folder,which I have not been able to figure out.
@user2784074: You need to use fso.CreateTextFile.
+1 for introducing this strange prefix that I missed until now. -1 for providing a solution for an unspecified requirement. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.