Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-03-30
8
Medium Priority
?
813 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 750 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

927 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