Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

Creating a word list using batch

I want to make a batch file that prints out to a text file a list of combination of numbers and letters.
Using {0, ..., 9, a, ..., z, A, ..., Z} as my character pool, I have 62 unique characters.
The word length starts as 1 and increases up to a predetermined value.

The script starts at length = 1 and prints out 0 to Z.
Then it proceeds to length = 2 and prints out 00 to ZZ, and so on...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is an iterative solution that is much faster.

No need for CALL. Each permutation is only generated once.

I was able to generate up to length 4 with over 15 million permutations in less than 5 minutes.

@echo off
setlocal enableDelayedExpansion
set chars=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
set maxPos=61
del output.txt 2>nul

>prior.txt echo(""
for /l %%I in (1 1 %1) do (
  >new.txt (
    for /f %%A in (prior.txt) do for /l %%N in (0 1 %maxPos%) do echo(%%~A!chars:~%%N,1!
  )
  type new.txt>>output.txt
  move /y new.txt prior.txt >nul
)
del prior.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...