Solved

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

Posted on 2009-03-30
8
810 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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