Solved

Need C# Help to create a "Push Button" Subfolder Heirarchy with nested Subfolders

Posted on 2009-03-30
8
809 Views
Last Modified: 2012-05-06
I need to make a file system that goes something like this:
Folder Level 1.) Top Folder (Brands - ex. WidgetCoWidgets, HelliCoWhirrleyGigs, etc.)
Folder Level 2.) Second Level Folder (BlueWidgets, GreyWidgets, RedWidgets)
Folder Level 3.) Are all of the Product SKUs (BW001, BWABC, BW3456D)
<!--  I have done the first three levels so far -- >
Here's where I need help ...
For each level 3 folder, I need to add 3 department styled folders (like, Sales, Marketing, Finance)
Then, within each fourth level folder I need to add another array of folders like (ProductBrochures,PriceLists,MarComMaterials).  I am not sure how to script the creation of the level four and five folders.  Is there some sort of silver bullet "For each subfolder in path X, add level 3 folder, then add level four folder?  The problem is, there is no serialization at the level 3 level.  The product names are largely random.  I would appreciate any help you could gibe to get me a simple ASP.NET solution that uses System.IO to manipulate all of this ...  
0
Comment
Question by:dude727
  • 6
  • 2
8 Comments
 
LVL 16

Expert Comment

by:t0t0
ID: 24027143
This will perform the task on the given foldernames:

@echo off
for %%a in (WidgetCoWidgets HelliCoWhirrleyGigs) do (
   if not exist %%a md %%a
   for %%b in (BlueWidgets GreyWidgets RedWidgets) do (
      if not exist %%a\%%b md %%a\%%b
      for %%c in (BW001 BWABC BW3456D) do (
         if not exist %%a\%%b\%%c md %%a\%%b\%%c
         for %%d in (Sales Marketing Finance) do (
            if not exist %%a\%%b\%%c\%%d md %%a\%%b\%%c\%%d
            for %%e in (ProductBrochures PriceLists MarComMaterials) do (
               if not exist %%a\%%b\%%c\%%d\%%e md %%a\%%b\%%c\%%d\%%e
)))))
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 250 total points
ID: 24027183
Another way to do it is as follows:

@echo off
for %%a in (WidgetCoWidgets HelliCoWhirrleyGigs) do (
   if not exist %%a md %%a
   cd %%a
   for %%b in (BlueWidgets GreyWidgets RedWidgets) do (
      if not exist %%b md %%b
      cd %%b
      for %%c in (BW001 BWABC BW3456D) do (
         if not exist %%c md %%c
         cd %%c
         for %%d in (Sales Marketing Finance) do (
            if not exist %%d md %%d
            cd %%d
            for %%e in (ProductBrochures PriceLists MarComMaterials) do (
               if not exist %%e md %%e
            )
            cd..
         )
         cd..
      )
      cd..
   )
   cd..
)


Or you could close up the closing brackets as in:

@echo off
for %%a in (WidgetCoWidgets HelliCoWhirrleyGigs) do (
   if not exist %%a md %%a
   cd %%a
   for %%b in (BlueWidgets GreyWidgets RedWidgets) do (
      if not exist %%b md %%b
      cd %%b
      for %%c in (BW001 BWABC BW3456D) do (
         if not exist %%c md %%c
         cd %%c
         for %%d in (Sales Marketing Finance) do (
            if not exist %%d md %%d
            cd %%d
            for %%e in (ProductBrochures PriceLists MarComMaterials) do (
               if not exist %%e md %%e
) cd.. ) cd.. ) cd.. ) cd.. )


0
 
LVL 16

Expert Comment

by:t0t0
ID: 24027229
To add random product names, you need to run this batch file passing it the product name as a command line parameter. You could also call this as a sub-routine inside an existing batch file or as an external batch file.

Example 1 (Run on the command line):

   ADDITEM BW002


Example 2 (External batch file CALLed from within another batch file):

   call additem BW002


Example 3 (Sub-routine CALL within a batch file):

   call :additem BW002


::ADDITEM.BAT
@echo off
if "%1"=="" exit /b 1
for %%a in (WidgetCoWidgets HelliCoWhirrleyGigs) do (
   for %%b in (BlueWidgets GreyWidgets RedWidgets) do (
      if not exist %%a\%%b\%1 md %%a\%%b\%1
      for %%d in (Sales Marketing Finance) do (
         if not exist %%a\%%b\%1\%%d md %%a\%%b\%1\%%d
         for %%e in (ProductBrochures PriceLists MarComMaterials) do (
            if not exist %%a\%%b\%1\%%d\%%e md %%a\%%b\%1\%%d\%%e
         )
      )
   )
)
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:dude727
ID: 24027911
Is there a way though to wildcard level 3 (product SKUs as above), rather than passing a string (BW001 BWABC BW3456D, etc.), as I have thousands of product folders to make the subfolder structure for? That would also mean I would need to know the level name of every folder, which I don't ...
0
 

Author Comment

by:dude727
ID: 24028210
Another thought, perhaps I have this in the wrong zone ... While batch files are OK, is there a way to do this in C# - please keep in mind, also, the folder strings at level 5 will vary by level 4 .... in other words, the level 4 Marketing folder may have a subfolder called SellSheets, while a level 4 "Finance" folder may have a child called "Cost Analysis".  They aren't all the same ... Any help you can offer would be appreciated ...
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24028446
The ADDITEM.BAt I wrote will create any randomly named folder at the third level and all sub-folders at higher levels.

If it fails to work on your system for some reason then please let me know...

0
 
LVL 16

Expert Comment

by:t0t0
ID: 24028521
I just did a tree of folders created by the first batch file and then added a product BW002. As can be seen, all appears to be well however, if there needs to be adjustments please confirm them here...


tree.txt
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24028574
Is there any particular reason why you would want to use a high level language such as C to perform this task? DOS batch files are more than adequate at doing what you want however, if you later want to, you can compile the batch file to an executable .EXE program with utilities such as BAT2EXE.

I program in C and C++ however, this particular task is best suited to DOS batch files. In C, there is so much to check for whereas DOS is designed to operate directly on file and folder structures.

I haven't yet encountered a problem I couldn't perform using DOS batch files.
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question