使用 VBS 创建文件夹和子文件夹

Create Folders and Subfolders using VBS

我希望能够在一个目录中创建一定数量的文件夹和子文件夹。我已经有一个循环遍历并创建文件夹和子文件夹的代码。无论如何要创建一定数量的这些文件夹?我也希望能够按顺序创建它们。例如,我已经有 2000 个文件夹。我想再创建一千个,但它会从 2001 年开始到 3000 年。我基本上想自动化我下面的代码,这样就没有人必须进入并不断更改脚本中的值。谢谢!

代码如下:

Dim oFSO,Folder
Set oFSO = CreateObject("Scripting.FileSystemObject")
For i = 1001 To 2000
 '  x=msgbox("Directorie " & i ,64, "MakeDir")

If Not oFSO.FolderExists(i) Then
  oFSO.CreateFolder i
End If
If Not oFSO.FolderExists(i & "/Text") Then
  oFSO.CreateFolder i & "/Text"
End If
If Not oFSO.FolderExists(i & "/Text") Then
  oFSO.CreateFolder i & "/Text"
End If
If Not oFSO.FolderExists(i & "/Text") Then
  oFSO.CreateFolder i & "/Text"
End If
If Not oFSO.FolderExists(i & "/TestData") Then
  oFSO.CreateFolder i & "/TestData"
End If
 Next

试试这个...

BaseFolder = "C:\temp"  'Root folder to look for/create subfolders in
MaxSize = 5             'the number of characters to allow in folder name
PaddingCharacter = "0"  'padding folder names with zeros for proper sorting
NumFolders = 10         'number of additional folder to create

intStart = GetLastFolder(BaseFolder)

If IsNull(intStart) Then
    intStart = 1
Else 
    'skip
End If

For i = intStart To intStart + NumFolders
    strFolderName = BaseFolder & "\" & RightPad( i, MaxSize, PaddingCharacter )
    Wscript.Echo strFolderName
    CreateFolders(strFolderName)
Next

Function GetLastFolder(strFolder)
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set objFolder = fso.GetFolder(BaseFolder)   
   Set subFlds = objFolder.SubFolders

    For Each fld in subFlds
        s = fld.Name
    Next

    x=Len(s)    
    For i=0 to x-1
        If Mid(s,i+1,1) = "0" Then
            'skip
        Else
            s = Mid(s,i+1,x)
            Exit For
        End If
    Next 

   GetLastFolder = s
End Function


Function CreateFolders(i)
    Dim oFSO,Folder
    Set oFSO = CreateObject("Scripting.FileSystemObject")

    If Not oFSO.FolderExists(i) Then
      oFSO.CreateFolder i
    End If
    If Not oFSO.FolderExists(i & "/Text") Then
      oFSO.CreateFolder i & "/Text"
    End If
    If Not oFSO.FolderExists(i & "/Text") Then
      oFSO.CreateFolder i & "/Text"
    End If
    If Not oFSO.FolderExists(i & "/Text") Then
      oFSO.CreateFolder i & "/Text"
    End If
    If Not oFSO.FolderExists(i & "/TestData") Then
      oFSO.CreateFolder i & "/TestData"
    End If
End Function

Function RightPad( strText, intLen, chrPad )
    'Example: RightPad( "1000", 7, "0" ) = "0001234"
    'Example: RightPad( "1000", 4, "0" ) = "1000"
    RightPad = Right( String( intLen, chrPad ) & strText, intLen )
End Function