• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2613
  • Last Modified:

How to write a batch file to create a folder structure using a master list of directory/sub-directory names or a "Table of Contents"

I have a master filing list of directories and sub directories (about 600+  that we use to create folders and sub folders in windows explorer - example -
1.1      General
1.1.1      File Index
1.1.2      Project Directory
1.1.3      Administration Correspondence

and we have sub folders under general using similar numbering structure -
What I could not figure out is how to get spaces and dots in the the batch file -
I did try the following dos bat file but it did not work -
I know there must be a simpler way of "calling a text file" containing this list to create a folder sturcture -

I bow to the superior knowledge out there -

Thanks
Bramha
Master-list.txt
0
bramha
Asked:
bramha
  • 5
  • 3
1 Solution
 
Brett CrawleyZone LeaderCommented:
Hi Bramha

The following batch file takes a file containing a list of directory names one per line as a parameter and will create the structure, this doesn't drill down though it simply creates a flat structure. Also the names must contain only characters valid in a directory name, for example a tab character may not be used but a space character may be used.

@ECHO OFF

IF "%~1" == "" GOTO :HelpMessage
SET INFile="%~f1"

FOR /F "delims=;" %%A IN ('TYPE %INFile%') DO CALL :ParseFile "%%A"
GOTO :ExitBatch

:ParseFile
md "%~1"
GOTO :ExitBatch

:HelpMessage
ECHO Usage FolderList.bat ^<filename^>
GOTO :ExitBatch

:ExitBatch

Regards

Brett
0
 
bramhaAuthor Commented:
Hello Brett -
Thank you for your patience and support -
Let me give this a try and will respond immediately

Best
Bramha
0
 
bramhaAuthor Commented:
Hello Brett -
Are "numbers" and "dots or Periods" valid characters - ?

Bramha
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Brett CrawleyZone LeaderCommented:
Hi Bramha

Numbers and dots should work fine, the only characters that are not allowed are those you cannot use within a filename. A filename cannot contain any of the following characters:

\ : * / " ? < > |

I tried the code here with the attached file and it worked fine, although all directories were created under the same directory.

However if you were to include the structure in a text file in this way outlined below it would create the complete tree structure but you would have to make sure that the parent directories were created first:

1.1 General
1.1 General\1.1.1 File Index
1.1 General\1.1.2 Project Directory
1.1 General\1.1.3 Administration Correspondence
1.2 Contracts and Proposals
1.2 Contracts and Proposals\1.2.1 General Agreement
1.2 Contracts and Proposals\1.2.2 Consultant RFPs

Hope that helps.

Regards

Brett
folder-list.txt
0
 
bramhaAuthor Commented:
Hi Bramha - I apologize for the late response - I am currently travelling - and have a 12 hr difference with the US -

Got It - let me give it a try - and I will post a response soon

Thank you for you help -

Best
Bramha -
0
 
bramhaAuthor Commented:
Hello Brett -

Fianlly I have edited the master list to reflect the changes that you suggested - (all 600 + directories) took a while -
Question to you -
What do I call the file - (currently named master-filing-list)
Where should it be located - path
Should I edit the batch file that you sent to refelect that name -
 -
Because i tried running the script and nothing happend -
Bramha
0
 
bramhaAuthor Commented:
Hello Brett -

Finally figured it out - thanks a ton - maybe for your research - I feel that there could be an easier way than creating all those sub-tree structure of the directory sturcture -

All said and done - you were wonderful - and thank you once again -

Best
Bramha
0
 
Brett CrawleyZone LeaderCommented:
Hi Bramha

It doesn't matter where your master-filing- list or where you put the batch script as long as you include the full paths or relative paths to them when you call the script and you need to be in the root directory where you want the directories to be created. For example assuming you have called the batch file FolderList.bat as I had and that you had placed it in c:\ and assuming that your master-filing-list.txt was in  
"c:\Some Directory\master-filing-list.txt", you simply call it as follows:

c:\FolderList.bat "c:\Some Directory\master-filing-list.txt"

from the directory where you want the structure to be created.

Regards

Brett
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now