+ Post New Thread
Results 1 to 8 of 8
Windows 7 Thread, Script to create 37 directories from a list of directory names in Technical; 1 would like to create 37 subfolders in the folder PanelA. I have a list in notepad for each subfolder ...
  1. #1

    Join Date
    Apr 2014
    Posts
    5
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Script to create 37 directories from a list of directory names

    1 would like to create 37 subfolders in the folder PanelA. I have a list in notepad for each subfolder name.

    I have here a basic script but I cannot get it to read the subfolder names in the notepad (or in the script)

    ParentFolder = "C:\"
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(ParentFolder)
    objFolder.NewFolder "R-"


    What shoul dI do to name these folders from the names:
    R-Ta
    R-61
    R-31
    R-Ty
    R-P1
    R-B3
    R-N2
    R-50
    R-1
    R-BN1
    etc

    Thanks

    Regards
    Raury

  2. #2

    Join Date
    Apr 2007
    Location
    Cornwall
    Posts
    275
    Thank Post
    18
    Thanked 76 Times in 48 Posts
    Rep Power
    36
    You could do it in DOS in one line:

    FOR /F "tokens=1 " %%i in (subfolders.txt) do mkdir c:\%%i

    Where subfolders.txt is your text file of sub folder names...

    HTH,

    Meldrew

  3. #3

    Join Date
    Apr 2014
    Posts
    5
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi Meldrew,

    I had the error message %%i was unexpected at this time. - please see attached.

    RauryEror.jpeg

  4. #4
    Fleetwood's Avatar
    Join Date
    Feb 2012
    Location
    Gloucestershire
    Posts
    715
    Thank Post
    162
    Thanked 89 Times in 50 Posts
    Rep Power
    41
    If you're running it directly from CMD you need to use %i rather than %%i, I think?

    EDIT: Yes, if you're inputting it directly in CMD you need to use %i, if running from a .bat then you use %%i
    Last edited by Fleetwood; 17th April 2014 at 04:11 PM.

  5. Thanks to Fleetwood from:

    Raury (22nd April 2014)

  6. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365
    Presume this is resolved using the bat script etc or did you want / need this in a different script ie vbs / powershell etc ?

  7. Thanks to mac_shinobi from:

    Raury (22nd April 2014)

  8. #6


    Join Date
    Jan 2012
    Posts
    2,618
    Thank Post
    934
    Thanked 351 Times in 267 Posts
    Rep Power
    213
    Quote Originally Posted by Meldrew View Post
    FOR /F "tokens=1 " %%i in (subfolders.txt) do mkdir c:\%%i
    See, I would have convoluted the heck out of it by writing it in powershell,

    Code:
    $SubfolderList = (Get-Content ...\subfolders.txt)
    [int]$counter = 0
    do {
    
    New-Item -ItemType directory -Path ...\$SubfolderList[$counter] $counter ++
    } until ($counter -eq $SubfolderList.Count+1)
    Because I can never get around all this FOR, %%i, etc it Batch. It just.. Makes no sense

    (Could probably use ForEach-Item in $SubfolderList, but I'm not entirely sure how I'd do it. So for now I'd bodge it with a counter)
    Last edited by Garacesh; 24th April 2014 at 01:59 PM.

  9. Thanks to Garacesh from:

    mac_shinobi (24th April 2014)

  10. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365
    Quote Originally Posted by Garacesh View Post
    See, I would have convoluted the heck out of it by writing it in powershell,

    Code:
    $SubfolderList = (Get-Content ...\subfolders.txt)
    [int]$counter = 0
    do {
    New-Item -ItemType directory -Path ...\$SubfolderList[$counter] $counter ++
    } until ($counter -eq $SubfolderList.Count+1)
    Because I can never get around all this FOR, %%i, etc it Batch. It just.. Makes no sense

    (Could probably use ForEach-Item in $SubfolderList, but I'm not entirely sure how I'd do it. So for now I'd bodge it with a counter)
    I'm the same ref makes no sense in batch with the FOR i%% etc, prefer vbs or powershell etc

  11. #8

    LeMarchand's Avatar
    Join Date
    Jan 2008
    Location
    The deepest pits of hell
    Posts
    2,178
    Thank Post
    303
    Thanked 332 Times in 236 Posts
    Rep Power
    141
    I cheat and use a small app called "Text2Folders".

    Though if I learned to script it, it would better in the "Give a man a fish/teach a man to fish" way!

SHARE:
+ Post New Thread

Similar Threads

  1. Script to create a VPN connection
    By Norphy in forum Scripts
    Replies: 5
    Last Post: 20th April 2010, 11:37 AM
  2. Replies: 1
    Last Post: 21st December 2007, 06:27 PM
  3. VB Script to create folders
    By markesmith in forum Scripts
    Replies: 2
    Last Post: 26th April 2007, 03:03 PM
  4. Script to Create My Documents Subject Folders
    By SwedishChef in forum Scripts
    Replies: 15
    Last Post: 5th July 2006, 08:14 AM
  5. Script to create a local user on a XP box.
    By tosca925 in forum Scripts
    Replies: 3
    Last Post: 12th October 2005, 12:04 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •