Automatic generation of folders and subfolders

J

jaustin

I would like to set up a group of folders numbered
sequentially 0000 to 10,000 with subfolders in each that
are given the same alphanumeric names in each folder. I
would like to be able later to add subfolders to all files
at one time and not have to do it individually. I want to
use these to store a large group of scanned text pdf
documents. Will windows 2000 support this and how can I
set this up at one time rather than each folder and
subfolder - one at a time? Is there a program that does
this or a series of windows commands that will do this?
 
T

Torgeir Bakken (MVP)

jaustin said:
I would like to set up a group of folders numbered
sequentially 0000 to 10,000 with subfolders in each that
are given the same alphanumeric names in each folder. I
would like to be able later to add subfolders to all files
at one time and not have to do it individually. I want to
use these to store a large group of scanned text pdf
documents. Will windows 2000 support this and how can I
set this up at one time rather than each folder and
subfolder - one at a time? Is there a program that does
this or a series of windows commands that will do this?

Hi

Below is a VBScript (put it in a file with .vbs as file extension and double
click on it) that will create folders from 0000 to 10000 in the folder
specified in the variable sBaseFolder.

The script will create a subfolder in the folders with the same name as the
parent folder, like this:

c:\something\0000\0000
c:\something\0001\0001

If that is not what you meant, you need to change the script line

sSubFolder = sFolder

to something else. If you wanted a fixed name for the subfolder, change it to
this:

sSubFolder = "something2"


The result will then be this:

c:\something\0000\something2
c:\something\0001\something2



' script start
Set oFSO = CreateObject("Scripting.FileSystemObject")

sBaseFolder = "c:\something\" ' note the terminating backslash

iStart = 0 ' will be converted to 0000 in the script below
iStop = 10000

On Error Resume Next ' in case the folder exists from before
oFSO.CreateFolder sBaseFolder
On Error Goto 0

For i = iStart To iStop
If i < 10000 Then
sFolder = Right("0000" & i, 4)
Else
sFolder = CStr(i)
End If

On Error Resume Next ' in case the folders exists from before
oFSO.CreateFolder sBaseFolder & sFolder

sSubFolder = sFolder
oFSO.CreateFolder sBaseFolder & sFolder & "\" & sSubFolder
On Error Goto 0
Next

MsgBox "Finished"
 
B

Bill James

A simple script can create the folder structure for you, although it will take several minutes with this many folders. I would recommend not starting at the root drive for this folder structure, but starting in a sub folder, and the computer you are creating the folders on should be formatted NTFS file system. I hope you have a big hard drive.

Here is a sample, you can easily change the starting folder and subfolder names.

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim BaseFldr
BaseFldr = "C:\aaaTest"

Dim Sub1, Sub2, Sub3, Sub4, Sub5
Sub1 = "Folder 1"
Sub2 = "Folder 2"
Sub3 = "Folder 3"
Sub4 = "Folder 4"
Sub5 = "Folder 5"

Dim i, s

If NOT fso.FolderExists(BaseFldr) Then fso.CreateFolder(BaseFldr)

For i = 0 to 10000
s = BaseFldr & "\" & Right("0000" & i, 5)
If NOT fso.FolderExists(s) Then fso.CreateFolder(s)
If NOT fso.FolderExists(s & "\" & Sub1) Then fso.CreateFolder(s & "\" & Sub1)
If NOT fso.FolderExists(s & "\" & Sub2) Then fso.CreateFolder(s & "\" & Sub2)
If NOT fso.FolderExists(s & "\" & Sub3) Then fso.CreateFolder(s & "\" & Sub3)
If NOT fso.FolderExists(s & "\" & Sub4) Then fso.CreateFolder(s & "\" & Sub4)
If NOT fso.FolderExists(s & "\" & Sub5) Then fso.CreateFolder(s & "\" & Sub5)
Next

MsgBox "Finished Creating Folders"

--

Bill James
Microsoft MVP - Shell/User

Win9x VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top