Search code examples
batch-filecoding-stylenumberspi

I want to take a string of numbers and turn each number into a text file title


I was looking to turn a string of numbers (A million digits of Pi). Each number I would like to become a file name

For Example

3.14159

I would like 3 to be a text file name
. to be a text file name
1 to be a text file name
4 to be a text file name
1 to be a text file name
5 to be a text file name
9 to be a text file name
and etc etc etc.

I have searched the internet but nothing has come up.

If anyone would be able to help me with the code for that it would be great!


Solution

  • I also don't get it what is your goal. I guess you want probably count the number of character in the string.

    Thus this can help:

    @echo off
    if not exist pi-folder\nul md pi-folder
    pushd pi-folder
    
    setlocal enabledelayedexpansion
    echo 3.1234567890abc>"%tmp%\pi.tmp"
    for %%l in ("%tmp%\pi.tmp") do set /a len=%%~zl
    set /a len-=2
    set /a count=len - 2
    echo:
    echo 3.1234567890abc count !count! characters after the dot
    echo:
    
    pause>nul
    rem create one file per character
    for /l %%i in (-1,-1,-%len%) do (
      for /f %%a in (%tmp%\pi.tmp) do (
        set char=%%a
        if "!char:~%%i,1!" neq "." (
          copy nul !char:~%%i,1!
        ) else (
          copy nul !char:~%%i,1!~
        )
      )
    )
    endlocal
    popd
    

    output:

    3.1234567890abc count 13 characters after the dot
    
    copy nul c
    copy nul b
    copy nul a
    copy nul 0
    copy nul 9
    copy nul 8
    copy nul 7
    copy nul 6
    copy nul 5
    copy nul 4
    copy nul 3
    copy nul 2
    copy nul 1
    copy nul .~
    copy nul 3
    

    result after dir /b:

    .~
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    a
    b
    c