Re: Creating a directory structure by McKirahan
McKirahan
Fri Feb 23 12:05:11 CST 2007
<trizzz@gmail.com> wrote in message
news:1172252214.041661.214760@p10g2000cwp.googlegroups.com...
> On Feb 23, 12:09 pm, "McKirahan" <N...@McKirahan.com> wrote:
> > <tri...@gmail.com> wrote in message
> >
> > news:1172249130.647072.72470@p10g2000cwp.googlegroups.com...
> >
> >
> >
> > > Please forgive my being a novice on the subject of scripting. I have
> > > no previous history with any type of coding (except a little HTML).
> >
> > > I'm not looking for the solution. I wouldn't ask that of anyone
> > > (unless you really want to give it to me). I've been a part of help
> > > forums before and I hate it when people have no desire to actually do
> > > it themselves.
> >
> > > What I am looking for is perhaps a good resource to begin researching
> > > the solution. What steps should I be looking to take?
> >
> > > Here's what needs to be accomplished:
> >
> > > The script needs to read a file (I'm not sure if it's an excel
> > > spreadsheet or a text document). In this document is a list of
> > > items. The script will need to create a folder with the names in the
> > > document. Then, the script needs to also create 10 subfolders with
> > > specific names. The names of the subfolders will be the same for all
> > > of the main folders. Within those subfolders, there'd be other
> > > subfolders, again - identical throughout.
> >
> > > The file that the script reads will only provide the names of the main
> > > folders.
> >
> > > Any information you can give would be greatly appreciated.
> >
> > > Thank you,
> > > TriZz
> >
> > > PS: I think my boss has me a bit over my head here.
> >
> > Determine the attributes and format of the source file.
> > A text file would be preferable; MS-Excel can be exported to one.
> > Is each folder name on a separate line? Are there any heading lines?
> >
> > How are the names of the subfolder and sub-subfolders determined.
> >
> > If there aren't very many folders in the source file you could manually
> > create the full structure under one folder via the command line (or via
> > a batch file) using "md" (or "mkdir" - Make Directory) then manually
> > copy the top-level folder to each other name via Windows Explorer.
> >
> > For example:
> >
> > @echo off
> > echo Folder.bat
> > echo.
> > cd \Temp
> > md Folder_1
> > md Folder_1\Folder_A
> > md Folder_1\Folder_A\Folder_A1
> > md Folder_1\Folder_A\Folder_A2
> > md Folder_1\Folder_B
> > md Folder_1\Folder_B\Folder_B1
> > md Folder_1\Folder_B\Folder_B2
> >
> > If there are numerous folder then look into FSO (FileSystemObject)
> > to read the file and cretae the folders and subfolders.
>
> The subfolder's names are already determined by the 'higher-ups' here
> at the office. I have a spreadsheet in front of me. I haven't seen
> the file yet with the information, but it is client numbers.
> Basically our structure will look something like this
>
> R:\client number (read from file)
> -subfolder1
> -sub-subfolder1
> -sub-subfolder2
> -sub-subfolder3
> -sub-subfolder4
> -sub-subfolder5
> -subfolder2
> -sub-subfolder6
> -sub-subfolder7
> -sub-subfolder8
> -subfolder3
> -sub-subfolder9
> -sub-subfolder10
> -sub-subfolder11
>
> (this is over simplified, but just used to show the point)
>
> There may be hundreds or even thousands of client numbers in the file,
> which is why they want me to use a script as an option. So, you're
> saying that FSO is my best option of research?
>
> - do you have any idea how difficult this may be for someone with
> little/none scripting history? I may just go to rent-a-coder if you
> think it may be too difficult of a task.
>
Here's a script that makes folders from a text file.
The text file contains one line per folder to be created.
If you're starting with an MS-Excel workbook then
create a copy of it, delete all but one worksheet, and
delete all columns but the one with client numbers
then export it (Save As) to a text file.
Adapt it to add the subfolder structure.
Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "folders.vbs"
Const cTXT = "folders.txt"
'*
'* Declare Variables
'*
Dim intDIR
intDIR = 0
Dim arrTXT
Dim intTXT
Dim strTXT
Dim strOTF
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
'*
'* Read Text File
'*
Set objOTF = objFSO.OpenTextFile(cTXT,1)
strOTF = objOTF.ReadAll
Set objOTF = Nothing
'*
'* Create Folders
'*
arrTXT = Split(strOTF,vbCrLf)
For intTXT = 0 To UBound(arrTXT)
strTXT = arrTXT(intTXT)
If strTXT <> "" Then
objFSO.CreateFolder(strTXT)
intDIR = intDIR + 1
End If
Next
'*
'* Finish Message
'*
Set objFSO = Nothing
MsgBox intDIR & " directories",vbInformation,cVBS