Document Creator in Batch

Introduction: Document Creator in Batch

About: I enjoy anything to do with computers. I have made some interesting scripts, and I am constantly improving my skill set. One day I hope to become a programmer, although in what category is still a mystery (al…

Once again, I made this instructable because it could be made. You don't need to use it or even acknowledge its existence.

Now, onto the specifics.

I made this "program" a rather long time ago. Well, at least the first version. It was originally called batch maker, but now it is called batch maker.

It was inspired by someone who said on my question (I delete it a while ago so this is not an exact quote) "Inspiration for batch files", where I asked for something to make with batch files. "Make a batch file to make your batch files." is along the lines of what he/she said.

Now, the features:
1. Can make all types of files*
2. Can delete, rename, edit and create files.
3. It has been added to my Mega_Menu instructable.

Now onto the code:

* Can only make files with extensions of two or three letters (Eg: .exe, .py, .bat, .txt). If no extension is added (or an extension with over 3 letters is recorded, ".txt" is added onto the end.

Step 1: Code

@echo off
setlocal enableextensions enabledelayedexpansion
title Document Creator
color f0

:Intro
cls
echo Welcome to Prof. Pickle's "Document Creator".
echo.
echo Here are your options:
echo 1) Create a new document
echo 2) Continue on with an existing document
echo 3) View an existing document
echo 4) Delete an existing document
echo 5) Rename an existing document
echo 6) Exit
choice /c 1234 /n
cls
if %errorlevel% equ 1 goto title
if %errorlevel% equ 2 goto continue
if %errorlevel% equ 3 goto exist
if %errorlevel% equ 4 goto delete
if %errorlevel% equ 5 goto rename
if %errorlevel% equ 6 goto exit

rem Setting the title of the document.
:title
set /p title=Title (Cannot have spaces in it):
rem Checking if an extension has been added (and adding ".txt" if it has not).
set check1=!title:~-4,1!
set check2=!title:~-3,1!
if %check1% neq . if %check2% neq . set title=%title%.txt
set num=0

rem Checking if a file of that title already exisits.
if exist %title% goto invalid

rem Making the contents of the document.
:lines
cls
set /a num=%num%+1
cls
if %num% gtr 1 (
echo Work so far:
echo.
if %num% gtr 1 type %title%
echo.
echo.
echo.
)
set /p line=Contents of line %num%:
goto create

rem Creating the document.
:create
echo %line% >> "%title%"
set line=
cls
echo Options:
echo 1) Continue
echo 2) Discontinue (delete file and go back to menu)
echo 3) Go back to main
echo 4) Exit
choice /c 123 /n
if %errorlevel% equ 1 goto lines
if %errorlevel% equ 2 goto discon
if %errorlevel% equ 3 goto intro
if %errorlevel% equ 4 goto exit

rem Informing you that a file of your title already exists.
:invalid
cls
echo A document with the title "%title%" already exists, pick a new one.
goto title

:discon
del %title%
exit

:exit
exit

:continue
cls
echo Note: File must be in the same directory.
set /p name=File name (and extension):
if not exist %name% goto invalid2
:lines2
cls
type %name%
echo.
echo.
set /p line=Next line:
echo %line% >> "%name%"
cls
echo 1) Continue
echo 2) Discontinue (exit and delete file)
echo 3) Go back to main
echo 4) Exit (save and exit)
choice /c 123 /n
if %errorlevel% equ 1 goto lines2
if %errorlevel% equ 2 goto discon2
if %errorlevel% equ 3 goto intro
if %errorlevel% equ 4 goto exit

:discon2
del %name%
exit

:exist
cls
set /p view=Type the name (and extension) of the file you want to view:
if not exist %view% goto invalid3
cls
type %view%
echo.
echo.
echo Press any key to go to menu
pause >nul
goto Intro

:invalid3
cls
echo No file of that name exists
echo.
echo Press any key to go back
pause >nul
goto Intro

:delete
cls
set /p del=Name of the file you want deleted (and extension):
if not exist %del% goto invalid3
cls
del %del%
echo Document has been deleted
echo.
echo.
echo Press an key to go back
pause >nul
goto intro

:rename
cls
set /p rename=Select the name of the document whose name you want to change (and extension):
if not exist %rename% goto invalid3
cls
set /p newname=Type the new name of the document (and extension):
if exist %newname% goto invalid4
set check1=!newname:~-4,1!
set check2=!newname:~3,1!
if %check1% neq . if %check2% neq . set newname=%newname%.txt
ren %rename% %newname%
cls
echo Press any key to go back to main
pause >nul
goto Intro

:invalid4
cls
echo A file of the name %newname% already exists.
echo.
echo Press any key to go back
pause >nul
goto rename

That's it. Once again, tell me if you need ANYTHING (emphasis on anything).

Step 2: Picture

Here's a picture |
                             \/

Be the First to Share

    Recommendations

    • Micro:bit Contest

      Micro:bit Contest
    • Reclaimed Materials Contest

      Reclaimed Materials Contest
    • Organization Contest

      Organization Contest

    Comments