1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Creating folders using a batch file

Discussion in 'Software' started by voodoo2k4, 13 Dec 2010.

  1. voodoo2k4

    voodoo2k4 Ghetto Modder

    Joined:
    21 Apr 2004
    Posts:
    316
    Likes Received:
    2
    Hello,

    I am always putting together folder structures on shared network drives for storing all kind of mindless crap at work. I have been using a batch file to create these folders and subfolders from a text file which contains a list of names. The batch file is as follows:

    Code:
    for /F "tokens=*" %%* in (file.txt) 
    do(mkdir 
    "P:\Services\%%*" 
    "P:\Services\%%*\Contracts" 
    "P:\Services\%%*\Monitoring" 
    "P:\Services\%%*\Reviews"
    )
    
    This would neatly create folders for each company listed in file.txt and then 3 sub folders as above. Something like this:

    Code:
    P:
      Services
          HSBC
               CONTRACTS
               MONITORING
               REVIEWS
          BARCLAYS
               CONTRACTS
               MONITORING
               REVIEWS
          LLOYDS
               CONTRACTS
               MONITORING
               REVIEWS
    This was great but was a while ago now and the amount of information stored is getting large. I now need to insert a subfolder in CONTRACTS and MONITORING for every provider called OLDER CONTRACTS and OLDER MONITORING.

    Does anyone know how that would work with a batch file. Presumable it is very simple! ASs it doesnt need a list etc - just do the same for every folder in a directory/drive.

    Ive experimented but can get it quite right and am rubbish with programming. Its not my job - Im a contracts officer but this makes my life a whole lot easier.

    Much kudos to anyone who can help.

    Dean.
     
    Last edited: 13 Dec 2010
  2. Zoon

    Zoon Hunting Wabbits since the 80s

    Joined:
    12 Mar 2001
    Posts:
    5,888
    Likes Received:
    824
    Code:
    for /F "tokens=*" %%* in (file.txt) 
    do(mkdir 
    "P:\Services\%%*" 
    "P:\Services\%%*\Older Contracts" 
    "P:\Services\%%*\Older Monitoring" 
    )
    
    ?
     
  3. voodoo2k4

    voodoo2k4 Ghetto Modder

    Joined:
    21 Apr 2004
    Posts:
    316
    Likes Received:
    2
    Hi Zoon,

    Line breaks added to make it readable on a forum post if thats what you mean?

    Dean.


    EDIT: Sorry - I need to put my glasses on!

    Yeah I should have mentioned that the original list of 300 odd folders came from a database. Since then folders names have been tweaked by users and some uneeded ones deleted etc. I dont even think I have the original text file either.

    Im just looking for a way of mindlessly creating a couple of sub directories in ALL of the folders regardless of names. A work around I suppose would be a way of merging all the current folder names into a text file by using a batch file. Then using this as you say. It has to be a batch file as no little apps allowed at work etc etc

    I keep nearly getting it but not quite - as I say I am not skilled/experienced in this area.

    Thanks,

    Dean.
     
    Last edited: 13 Dec 2010
  4. Zoon

    Zoon Hunting Wabbits since the 80s

    Joined:
    12 Mar 2001
    Posts:
    5,888
    Likes Received:
    824
    Okay so basically you need to create the list again in that case.

    The easiest way IMO will be to:

    1. Open a command prompt and type

    Code:
    dir /A:D > c:\folder_list.txt
    2. Open Microsoft Excel and open c:\folder_list.txt as a tab-delimited text file, making sure that the column seperator puts the folder names in a column, doesn't really matter about the rest.

    3. Chop the first three lines and the bottom two, so all you're left with is a list of folders, and some garbage data you don't care about.

    4. Delete the other column(s).

    5. Run your new script as above. (I would suggest you test it on a test folder with a handful of folders first just in case!!!)

    6. Profit????
     
  5. voodoo2k4

    voodoo2k4 Ghetto Modder

    Joined:
    21 Apr 2004
    Posts:
    316
    Likes Received:
    2
    Thanks Zoon,

    Unfortunately I dont think I have root access but can probably make that work around work somehow.

    It just seems that surely there is an easier way to create a folder in every folder. Removing the tokens section of the batch etc and just mkdir "a directory" repeat or continue etc etc

    Is there such a way or am I a silly billy?!? :)

    Dont know what you mean by profit? Looking for moolah? I work for the local council social services and get F all. Although if anyone could solve the problem with a mini batch I could make a token PayPal gesture of festive god will!

    Thanks,

    Dean.
     
  6. Zoon

    Zoon Hunting Wabbits since the 80s

    Joined:
    12 Mar 2001
    Posts:
    5,888
    Likes Received:
    824
    The "profit???" bit is just a pop-culture reference mate :)

    If you don't have root access or can't write to your C:, write to your personal directory or personal network drive.

    If you can't get into command prompt, write a new batch file called makelist.bat and drop the code I gave you, replacing c:\ with h:\ or whatever your personal drive is on your network!

    KISS - Keep It Simple, Stupid - you have a script that already works, you just need to give it a list of folders :thumb:
     

Share This Page