Jump to content

Script to create 37 directories from a list of directory names


Recommended Posts

Posted

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

Posted

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

Posted (edited)

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

Edited by Fleetwood
  • Thanks 1
Posted (edited)
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,

 

$SubfolderList = (Get-Content ...\subfolders.txt)
[int]$counter = 0
do {


[indent]New-Item -ItemType directory -Path ...\$SubfolderList[$counter]
$counter ++[/indent]


} 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)

Edited by Garacesh
  • Thanks 1
Posted
See, I would have convoluted the heck out of it by writing it in powershell,

 

$SubfolderList = (Get-Content ...\subfolders.txt)
[int]$counter = 0
do {

[indent]New-Item -ItemType directory -Path ...\$SubfolderList[$counter]
$counter ++[/indent]


} 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...