34

I need 100 or more folders named like such: ch.000, ch.001, ch.002, etc. In this case I need it to go up to ch.094 but I will need to create more folders later. That may be more or less folders, but definitely between 000 and 999. I don't know anything about programming, so please guide me through it.

Here is an example of what I need to do.

Screenshot of folders ch.000 to ch.012

Thank You!

TRiG
  • 1,360
Safwan Abrar
  • 492
  • 1
  • 4
  • 8

6 Answers6

50

Create a .bat file inside the folder in which to create these sub-folders, and copy inside the following text:

@echo off
setlocal enableDelayedExpansion
FOR /l %%N in (1,1,94) do (
    set "NUM=00%%N"
    set "DIRNAME=ch.!NUM:~-3!"
    md !DIRNAME!
)

Double-click the .bat file and it will create the required chapters.

In the future, if you wish to create for example numbers 95 to 110, just change the FOR line to:

FOR /l %%N in (95,1,110) do (
harrymc
  • 498,455
38

Here's a PowerShell script:

for ($i=1; $i -lt 95; $i++) {
  $name = [string]::Format("ch.{0}", $i.ToString("000"));
  New-Item -Path "c:\source\temp" -Name $name -ItemType "directory"
}

Assuming you're on Windows, you can do Start > Run > "powershell.exe" > OK, then copy/paste this to the command line.

Note that you'll want to change c:\source\temp to the directory where you want the folders, and you can adjust the range to be created by adjusting the values in the for statement, where you see 1 and 95.

OrangeDog
  • 1,310
14

I believe there now is a Linux subsustem in Windows (I've never used it - in fact, I don't use Windows at all), so you could use a bash script - type it on the command line in a bash shell (is that the term in windows? - and note that '$' is the bash-prompt):

$ for i in $(seq -w 1 100)
> do
> mkdir ch.$i
> done

Personally I think it looks better than the powershell version - not least because you can split commands that take a block, over several lines.

j4nd3r53n
  • 429
9

The free Total Commander can create multiple folders with one command since version 9.10 (2017).

Press F7 to open the Create Directory dialog, then enter

<1-99>ch.[C:3]

as shown below, and it will create the folders you need.

Total Commander New Folder dialog with counter

The complete syntax is as follows, with begin, step and width being optional:

<(counterstart)-(counterend)>sometext[C(begin)(+-)(step):(width)]sometext

Previous answer:

It also has a GUI for renaming things, useful if you already have the right number of directories but with wrong names (such as by copy-pasting lots of empty dirs).

Select the folders and open Files -> Multi-Rename Tool. The image shows settings that rename all folders to the scheme you want.

enter image description here

Felix Dombek
  • 2,175
8

If you can run Linux commands on Windows, the most succinct way would probably be:

mkdir ch.{000..099}

If that doesn't work (because you use ksh or otherwise), then this should work:

mkdir $(printf 'ch.%s\n' $(seq -w 000 099))
JoL
  • 377
0

You can easily use CFolder software.

Download form GitHub