How do I open a text file to edit DIRECTLY in batch? - batch-file

Batch language.
So, I made a small text editor called microPad. It can create a file, but I don't know how to have it open a file and write to it. Any ideas?
(I want to add another marker block called 'oeditor' at the end, after 'neditor'
#echo off
color c
title microPad v1.02
:options
echo ----------------------------------
echo microPad v1.02
echo ----------------------------------
echo.
echo 1 - Create a new document.
echo 2 - Preferences.
set /p opt=Select an option number.
if %opt%==1 goto neditor
if %opt%==2 goto prefs
if NOT %opt%==2 goto notopt
:notopt
cls
echo That isn't an option.
timeout -t 1 >nul
cls
goto options
:prefs
cls
echo 1 - Change the color.
echo 2 - Change the window size.
echo 3 - Return to options screen.
set /p prefopt=^>^>
if %prefopt%==1 goto colorpref
if %prefopt%==2 goto sizepref
if %prefopt%==3 goto options
if NOT %prefopt%==3 goto notopt
:colorpref
cls
set /p colors=^>^>
color %colors%
goto prefs
:sizepref
cls
echo The size should be between 50 and 1000.
set /p size=^>^>
mode %size%
:titling
echo ----------------------------------
echo microPad v1.02
echo ----------------------------------
echo.
echo.
echo Input the filename and remember to use the file extension.
set /p fname=">> "
timeout -t 1 >nul
title %fname% - microPad v1.02
cls
echo ----------------------------------
echo microPad v1.02
echo ----------------------------------
echo.
:neditor
set /p content=">> "
echo %content%>>%fname%
goto neditor

Related

How to do addition in a batch file using numbers set in text files

I want to set a text file to a specific number, and then add it to the number stated in the batch file.
:opt21
cls
echo Account Balance
echo _______________________________________________________
type "C:\Users\Accounts\%log%.%pas%\bal.txt"
pause
goto login
:opt23
cls
set /a lab=<C:\Users\Accounts\%log%.%pas%\bal.txt
echo Account Deposit
echo _______________________________________________________
set /p da=Deposit Ammount (In $):
set /a tda= %lab% + %da%
:setop
cls
echo Account Deposit
echo _______________________________________________________
echo Your new balance will be $%tda%, continue?
set /p yn2=(Y/N):
if "%yn2%"=="Y" goto tda
if "%yn2%"=="N" goto opt21
cls
echo Sorry, "%yn2%" is not valid.
pause
goto setop
:tda
cls
del /F /Q "C:\Users\Accounts\%log%.%pas%\bal.txt"
break >"C:\Users\Accounts\%log%.%pas%\bal.txt"
echo %tda% >>"C:\Users\Accounts\%log%.%pas%\bal.txt"
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo .
echo New Balance Set
timeout /t 2 >nul /nobreak
cls
goto opt21
What it's supposed to do is take the number that is inside of C:\Users\Accounts\%log%.%pas%\bal.txt and add it to the number specified by the user in the variable "%da%", what it does currently is take the number specified by the user in the variable "%da%" and makes that the number in the file, it doesn't add it at all, it just replaces it.

How to write to different lines of a text file with batch

I wrote the following code:
#echo off
title Kiel Configurations
rem Credits Will Go Here
rem Website Here
color 08
echo **********************************************************************
echo **************************Kiel Configuration**************************
echo **********************************************************************
echo ======================================================================
echo Use yes/no to configure the following options
pause
cls
echo Would you like it to run in fake mode? (recommended for slow computers or for the paranoid)
set /p FakeModeVar=(yes/no):
cls
echo Would you like to close skype?
set /p SkypeVar=(yes/no):
cls
echo Woud you like to close spotify?
set /p SpotifyVar=(yes/no):
cls
echo Would you like to close steam?
set /p SteamVar=(yes/no)
cls
echo Would you like to close chrome? (reccommended)
set /p ChromeVar=(yes/no):
cls
echo Which chrome profile would you like chrome to open as? (Ask me if unsure)
set /p ChromeProfile=(1,2,3...):
cls
echo Now configurating you settings...
pause >nul
if %FakeModeVar%==yes goto Locate1
if %FakeModeVar%==no goto Locate2
:Locate1
echo yes> ConfigVarini.txt
goto Locate3
:Locate2
echo no> ConfigVarini.txt
goto Locate3
:Locate3
if %SkypeVar%==yes goto Locate4
if %SkypeVar%==no goto Locate5
:Locate4
echo yes>> ConfigVarini.txt
goto Locate6
:Locate5
echo no>> ConfigVarini.txt
goto Locate6
:Locate6
if %SpotifyVar%==yes goto Locate7
if %SpotifyVar%==no goto Locate8
:Locate7
echo yes>>> ConfigVarini.txt
goto Locate9
:Locate 8
echo no>>> ConfigVarini.txt
goto locate9
:Locate9
if %SteamVar%==yes goto Locate10
if %Steamvar%==no goto Locate11
:Locate10
echo yes>>>> ConfigVarini.txt
goto Locate12
:Locate11
echo no>>>> ConfigVarini.txt
goto Locate12
:Locate12
if %ChromeVar%==yes goto Locate13
if %ChromeVar%==no goto Locate14
:Locate13
echo yes>> ConfigVarini.txt
goto Locate15
:Locate14
echo no>>>>> ConfigVarini.txt
goto Locate15
:Locate15
if %ChromeProfile%==1 goto Locate16
if %ChromeProfile%==2 goto Locate17
if %ChromeProfile%==3 goto Locate18
:Locate16
echo 1>>>>> ConfigVarini.txt
goto End
:Locate17
echo 2>>>>>> ConfigVarini.txt
goto End
:Locate18
echo 3>>>>>> ConfigVarini.txt
goto End
:End
cls
echo Files Configured!
When i run it i want it to take the user through a configuration process then save their preferences to a text file called ConfigVarini.txt
Then i will have another program that reads the settings on the text file. However the file on says
yes yes
and it saves no other settings.
You can append to a batch file using ">>"
#echo off
echo Hi >> test.txt
echo Hello >> test.txt
echo. >>test.txt
echo 3 >> test.txt
Results in A file called test.txt containing
Hi
Hello
3
Im not sure what excatly you want besides this.
Also its good practice to leave a space before a inputting to a file since numbers from one to nine will cause problems.
Imho best practice: initially, empty your output file using
type nul> ConfigVarini.txt
and all further writing by either
(ECHO any text)>> ConfigVarini.txt
or
>> ConfigVarini.txt (ECHO any text)
Note:
no space preceding > nor >> redirection operator nor ) closing parenthesis. Otherwise, that space appears as a trailing one in output file (could be at least weird or even harmful);
() parentheses: important if output text ends with a single digit 0, 1, ..., 9 .
Explication (examples given with 1 but valid for any single decimal digit):
echo 1>> ConfigVarini.txt appends nothing (or an empty line or ECHO is on/off text) to output file as the CLI or batch parser treats a single decimal digit as the numeric file handle to be redirected (see redirection link above);
echo 1 >> ConfigVarini.txt appends 1 with trailing space;
>> ConfigVarini.txt ECHO 1 appends 1 but we can't be sure whether there is an unwanted (forgotten) trailing space;
>> ConfigVarini.txt (ECHO 1) appends 1 without trailing space;
(echo 1)>> ConfigVarini.txt appends 1 without trailing space;
More explanation and discussion here
One single > will overwrite whatever might be in ConfigVarini.txt and add only ONE line. Two >> will add another line on a new line and leave the previously written content intact. With the code below each time Locate1 or Locate2 is started old settings will be overwritten and new ones applied. (I didn't properly check all the code, only changed your flawed >> usage. Someone check and edit if needed)
#echo off
title Kiel Configurations
rem Credits Will Go Here
rem Website Here
color 08
echo **********************************************************************
echo **************************Kiel Configuration**************************
echo **********************************************************************
echo ======================================================================
echo Use yes/no to configure the following options
pause
cls
echo Would you like it to run in fake mode? (recommended for slow computers or for the paranoid)
set /p FakeModeVar=(yes/no):
cls
echo Would you like to close skype?
set /p SkypeVar=(yes/no):
cls
echo Woud you like to close spotify?
set /p SpotifyVar=(yes/no):
cls
echo Would you like to close steam?
set /p SteamVar=(yes/no)
cls
echo Would you like to close chrome? (reccommended)
set /p ChromeVar=(yes/no):
cls
echo Which chrome profile would you like chrome to open as? (Ask me if unsure)
set /p ChromeProfile=(1,2,3...):
cls
echo Now configurating you settings...
pause >nul
if %FakeModeVar%==yes goto Locate1
if %FakeModeVar%==no goto Locate2
:Locate1
echo yes > ConfigVarini.txt
goto Locate3
:Locate2
echo no > ConfigVarini.txt
goto Locate3
:Locate3
if %SkypeVar%==yes goto Locate4
if %SkypeVar%==no goto Locate5
:Locate4
echo yes >> ConfigVarini.txt
goto Locate6
:Locate5
echo no >> ConfigVarini.txt
goto Locate6
:Locate6
if %SpotifyVar%==yes goto Locate7
if %SpotifyVar%==no goto Locate8
:Locate7
echo yes >> ConfigVarini.txt
goto Locate9
:Locate 8
echo no >> ConfigVarini.txt
goto locate9
:Locate9
if %SteamVar%==yes goto Locate10
if %Steamvar%==no goto Locate11
:Locate10
echo yes >> ConfigVarini.txt
goto Locate12
:Locate11
echo no >> ConfigVarini.txt
goto Locate12
:Locate12
if %ChromeVar%==yes goto Locate13
if %ChromeVar%==no goto Locate14
:Locate13
echo yes >> ConfigVarini.txt
goto Locate15
:Locate14
echo no >> ConfigVarini.txt
goto Locate15
:Locate15
if %ChromeProfile%==1 goto Locate16
if %ChromeProfile%==2 goto Locate17
if %ChromeProfile%==3 goto Locate18
:Locate16
echo 1 >> ConfigVarini.txt
goto End
:Locate17
echo 2 >> ConfigVarini.txt
goto End
:Locate18
echo 3 >> ConfigVarini.txt
goto End
:End
cls
echo Files Configured!

Batch file closing instead using "goto" command

My code is not completely finished but it was working.Now it closes after the first section instead of going to section two.I know that this is probably a dumb mistake but I would appreciate the help!(The lines are just for organization)
#echo off
title First batch file
color 1f
::-----------------------
----------
:one
cls
echo Please enter your
name below.
echo.
echo.
set /p name=Name:
echo.
echo.
echo Hello %name%!
echo.
echo.
pause >nul
goto two
::-----------------------
----------
:two
cls
echo Would you like to
create a new account?
echo (yes or no)
echo.
echo.
set /p yorn=>>
if yorn equ yes then goto
new
if yorn equ no then goto
login
pause >nul
::-----------------------
---------
:new
cls
echo Please enter your
user name.
echo.
echo.
set /p username=Username:
cls
echo.
echo Please enter your
password.
echo.
echo.
set /p password=Password:
cls
echo.
echo Please confirm your
password.
echo.
echo.
set /p cpassword=Confirm
password:
cls
echo.
echo.
if %password% equ
%cpassword% goto
confirmscreen
if %password% new
%cpassword% goto new
pause >nul
:------------------------
---------
:confirmscreen
cls
echo Confirm:
echo.
echo.
echo Username: %username%
echo.
echo Password: %password%
echo.
echo.
set /p yorn2=Yes or No?:
if yorn2 equ yes goto
login
if yorn2 equ no goto new
pause >nul
:------------------------
---------
#echo off
title First batch file
color 1f
::---------------------------------
:one
cls
echo Please enter your name below.
echo.
echo.
set /p name=Name:
echo.
echo.
echo Hello %name%!
echo.
echo.
pause >nul
goto two
::---------------------------------
:two
set /p yorn=Would you like to create a new account? (yes or no) :
if %yorn% equ yes then goto new
if %yorn% equ no then goto login
goto:two

Batch File path vairiable %PATH%

I have been creating a chat room for my school, but I have to bring home the file to make changes as they become needed but my problem is the file path has to be changed each time I move the files from one system to another. so I would like to know how to create a %PATH% that will work for me
This is my full code for the main file:
As you may notice I'm new to this
NOTE: Everything here works fine with a set file path but I want it to work easier for when I change computers.
Anything could probably help
#echo off
:Tittle
cls
color 74
title Terms of Service
echo _________________________-Terms-______________________________
echo If you are using this ChatRoom then you agree to the following.
echo *you will not use Horrid Language
echo *you will make your account with either your real name or
echo Student id
echo.
echo This is monitored everyday so if anything is out of line it will be removed.
echo.
echo If you agree to follow these terms then type "yes" otherwise exit.
set /p c=Do you Agree to follow the terms?:
if %c% EQU yes goto Menu
if %c% EQU ADMIN1423 goto Admin
if %c% EQU dad goto Menu
if %c% EQU carrie goto Menu
if %c% EQU dad SET PATH=%PATH%;c:\Users\Dan W Frye\Desktop\(-_-)
:Admin
color 02
cls
Echo
Echo.
Echo 1.) Check User list
Echo.
Echo 2.) Create File Path
Echo.
Echo 3.) Admin Help
Echo.
echo 4.) N/A
echo.
Echo
set /p c=Selection Number:
if %c% EQU 1 goto UserList
if %c% EQU 2 goto CreatePath
if %c% EQU 3 goto AdminHelp
if %c% EQU 4 goto Admin
if %c% EQU back goto Tittle
:UserList
color 0b
cls
title User Listing
cls
start cmd
CALL "%PATH%\Data\Chat Settings\Users\BuAsTeCrHs.bat"
pause
goto Admin
:CreatePath
cls
color 01
echo
echo.
echo The File Path Must look like this(No " "): "Driver (C:)"\Containing folder" thats it the echo rest is automatically "\Data\Chat Settings\Users\....."
echo.
echo
echo.
echo The File Path you want to create.
set /p PATH=File Path:
echo.
echo The Location/Device you are using.
set /p LOC=Location:
echo.
echo %PATH% >>"%PATH%\Data\Chat Settings\File Paths\%LOC%.txt"
echo The file path has been created!
pause
goto Admin
:AdminHelp
pause
goto Tittle
:Menu
color 0b
cls
Echo -[ChatBox]-
Echo
Echo.
Echo 1.) Login
Echo.
Echo 2.) Register
Echo.
Echo 3.) Exit
Echo.
echo 4.) Help
echo.
Echo
Echo.
set /p c=Selection Number:
if %c% EQU 1 goto Login
if %c% EQU 2 goto Register
if %c% EQU 3 exit
if %c% EQU 4 goto help
if %c% EQU 5 goto Terms
:help
cls
echo if you are not able to see the chat log then you must not have
echo the file "Chatroom_reader.bat" open without this you cannot see
echo messages sent by other users.
echo.
echo if you have suggestions or comments then please type "comment"
echo.
echo if you need assistance with any other problem you may have
echo encountered then please type "other" to let the developer know
echo what the problem is. otherwise type "back" to go back to the menu.
set /p c=Option:
if %c% EQU comment goto comments
if %c% EQU other goto other
if %c% EQU back goto menu
:comments
cls
title Comments
echo Enter your Username, and Password to Place a Comment
echo.
set /p UN=Username:
echo.
set /p PW=Password:
echo.
if NOT Exist "%PATH%\Data\Chat Settings\Users\%UN%.txt" Goto Failed
echo %PW% >"%tmp%\chat.tmp"
fc "%tmp%\chat.tmp" "%PATH%\Data\Chat Settings\Users\%UN%.txt" >nul
if errorlevel==1 goto Failed
if errorlevel==0 goto Comment
:Comment
cls
echo.
set /p SUBJECT=Subject:
echo.
set /p COMMENT=Comment:
echo.
echo %SUBJECT% : %COMMENT% >"%PATH%\Data\Chat Settings\Comments\%UN%.txt"
goto User
:other
cls
title Other
echo Enter your Username, and Password to Place a Comment
echo.
set /p UN=Username:
echo.
set /p PW=Password:
echo.
if NOT Exist "C:\Users\Dan W Frye\Desktop\(-_-)\Data\Chat Settings\Users\%UN%.txt" Goto Failed
echo %PW% >"%tmp%\chat.tmp"
fc "%tmp%\chat.tmp" "C:\Users\Dan W Frye\Desktop\(-_-)\Data\Chat Settings\Users\%UN%.txt" >nul
if errorlevel==1 goto Failed
if errorlevel==0 goto OtherA
:OtherA
cls
set /p OTHERC=Other Concern:
echo.
echo %OTHERC% >"%PATH%\Data\Chat Settings\Other\%UN%.txt"
goto User
:Login
cls
echo Enter your Username, and Password to login to the Chat Server
echo.
set /p UN=Username:
echo.
set /p PW=Password:
echo.
if NOT Exist "%PATH%\Data\Chat Settings\Users\%UN%.txt" Goto Failed
echo %PW% >"%tmp%\chat.tmp"
fc "%tmp%\chat.tmp" "%PATH%\Data\Chat Settings\Users\%UN%.txt" >nul
if errorlevel==1 goto Failed
if errorlevel==0 goto User
:User
cls
Echo Welcome %UN% The Current date is %date%
echo
echo.
echo 1.) Chat
echo.
echo 2.) Logout
echo.
echo 3.) Change Password
echo.
echo 4.) Private Chat
echo.
echo 5.) Enter a Private Chat room
echo.
echo
set /p c=Selection Number:
if %c% EQU 1 goto chat
if %c% EQU 2 goto Menu
if %c% EQU 3 goto CHP
if %c% EQU 4 goto PRIVATE
if %c% EQU 5 goto PRIVATENTER
:PRIVATENTER
echo Please enter the name of the Private chat room if you do not know the name you may not enter.
set /p Chat=
if %Chat% EQU scooter goto scooter
if %Chat% EQU Cre-Br goto Cre-Br
:Cre-Br
cls
set name=[%time%]%UN%
cls
color 02
echo Last Message sent by %UN% \/
echo [%time%]%UN%:%text%
set /p text=Say:
echo %name% : %text% >>"%PATH%\Data\Chat Settings\Program_Files\Cre-Br.txt"
goto Cre-Br
:scooter
cls
echo %Chat%
set name=[%time%]%UN%
color 02
echo Last Message sent by %UN% \/
echo [%time%]%UN%:%text%
set /p text=Say:
echo %name% : %text% >>"%PATH%\Data\Chat Settings\Program_Files\scooter.txt"
goto scooter
:PRIVATE
cls
set /p Chat=Chat Name:
echo this is %UN%s Private chat room >>"%PATH%\Data\Chat Settings\Program_Files\%Chat%.txt"
echo.
echo #echo off >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo color 0b >>"%PATH%H:\(-_-)\Data\Chat Settings\Private Chats\%Chat%.bat"
echo cls >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo title Message Box >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo :home >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo cls >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo findstr /v "g91dhjt637hsuexv27niw9" "%PATH%\Data\Chat Settings\Program_Files\%Chat%.txt" >>"C:\Users\Dan W Frye\Desktop\Batch\Chat Settings\Private Chats\%Chat%.bat"
echo goto home >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
goto User
:CHP
cls
set /p PW=Old Password:
echo.
set /p NP=New Password:
echo %NP% >"%PATH%\Data\Chat Settings\Users\%UN%.txt
goto User
:Register
cls
color 07
echo Register (Note the username is your screen name Please use your real name or School ID EX, CaBu56789)
echo.
set /p NU=Username:
echo.
set /p NP=Password:
echo.
echo %NP% >"%PATH%\Data\Chat Settings\Users\%NU%.txt"
echo.
cls
goto login
:Failed
color 0c
cls
echo You have entered am invalid Username and or Password
echo Please try again or Register for free
pause
goto menu
:chat
set name=[%time%]%UN%
cls
color 02
echo Everything said here is on recored please mind your
echo language!
echo Last Message sent by %UN% \/
echo [%time%]%UN%:%text%
set /p text=Say:
echo %name% : %text% >>"%PATH%\Data\Chat Settings\Program_Files\ChatRoom.txt"
goto chat
%PATH% is reserved environment variable, documented here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/path.mspx?mfr=true
For diagnostics purposes you could echo that variable to analyze if that has such value you intended to have:
echo %path%
As mentioned by #Jermu Virtanen the %PATH% variable is a windows system set path...you should not use/change it unless you really know what you are doing.
So instead of using %PATH% use something like %PROGPATH%.
Also as mentioned by #foxdrive, if the user enters "dad" it will go to "menu" before setting the path variable. And again if you instead chose 'Admin' then to 'List users' it will again be calling the path without first setting it.
You could automate some of the login or path settings by grabbing the computer's domain name %userdomain% and current user %username%.
Ie;
SET "progpath=c:\Users\%username%\Desktop\(-_-)"
In your code the path was being set after it had already branched to the menu. This may work for you:
if %c% EQU carrie goto Menu
if %c% EQU dad SET PATH=%PATH%;c:\Users\Dan W Frye\Desktop\(-_-)& goto menu
To put the batch file on the path for every user, use this:
set path=%path%;%PUBLIC%
and copy the batch file to C:\Users\Public and run it from there.
Unless it needs extra permissions it should run from there for every user.

"access denied" error message for a text file i just made?

About 3 days ago I asked a question, which can be found here:
how to replace a string on the second line in a text file using a batch file?
I'm converting the letters in a text file into their respective numbers. I'm getting error messages such as "Access denied" and "Cannot locate this file" -- but the same batch file that's giving me all these errors is also the one that made these text files to begin with! So it should be in the same directory as the batch file itself (unless specified otherwise), right? I even went to that folder and checked, and they're there.
I did add a small script to hide the files after they were created so that it wouldn't look so cluttered up. I did this by using
attrib +h C:\script\%name%.txt
Would hiding a file with this command make it invisible to batch programs that are searching for it/call upon it?
Here's a link to the file, "stringparsing.bat": http://uploading.com/files/a1m1d2f4/stringparsing.bat/
If you could assist me in getting this program to carry out its task without any errors it would be greatly appreciated!
Here's the "stringparsing.bat" file in full:
#echo off
setlocal enabledelayedexpansion
title BETA
cls
cd C:\script\st
echo.
echo.
echo.
echo Setting Variables...
echo Loading Language Database...
:: ###################################################################################
:: CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE
:: ###################################################################################
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:MAIN
set foo=0
cls
echo.
echo.
echo.
echo.
echo ===================================
echo #################################
echo ####### Main Menu: #######
echo #################################
echo ===================================
echo.
echo.
echo 1.) Create New Language File...
echo.
echo 2.) Load Existing Lanuage File...
echo.
echo 3.) Settings...
echo ---------------------------------------------------------
SET /p CHOICE= Select a Function:
IF %CHOICE%== 1 GOTO CREATE
IF %CHOICE%== 2 GOTO LOAD
IF %CHOICE%== 3 GOTO SETTINGS
GOTO MAIN
:CREATE
cls
title Step 1
echo.
echo.
echo.
echo =================================================================================
echo.
set /p name= please type a name for your new language file:
echo.
echo =================================================================================
cls
echo. > %name%.txt
echo.
echo.
echo.
echo ==============================================================
echo ##############################################################
echo #============================================================#
echo # #
echo # - After you hit enter you will be redirected #
echo # to a Live Typer. so anything you type into #
echo # it will be sent to %name%.txt. #
echo # #
echo # #
echo # - Next, select load language File For Encoding! #
echo # #
echo #============================================================#
echo ##############################################################
echo ==============================================================
set /p line1= :
echo %line1% >> %name%.txt 2> nul
echo %name% > Language_File.txt
attrib +h Language_File.txt
set /a foo+ =1
)
echo.
echo ==========================================================
goto LOAD
:LOAD
set /a foo+ =1
IF %foo%== 2 goto loadexternal
goto LOAD23
:loadexternal
echo.
echo language file is loading now!
set /p name=<Language_File.txt
timeout /t 4 /nobreak > nul
echo.
echo.
echo Language_File Loaded!
pause >nul
goto LOAD23
:LOAD23
cls
echo.
echo.
echo.
echo.
echo.
echo Encoding Your Language File... Please Wait...
echo.
echo.
echo.
for /f "delims=" %%i in (!name!.txt) do (
echo translating "%%i"
set var=%%i
set var=!var:a=1 !
set var=!var:b=2 !
set var=!var:c=3 !
set var=!var:d=4 !
set var=!var:e=5 !
set var=!var:f=6 !
set var=!var:g=7 !
set var=!var:h=8 !
set var=!var:i=9 !
set var=!var:j=10 !
set var=!var:k=11 !
set var=!var:l=12 !
set var=!var:m=13 !
set var=!var:n=14 !
set var=!var:o=15 !
set var=!var:p=16 !
set var=!var:q=17 !
set var=!var:r=18 !
set var=!var:s=19 !
set var=!var:t=20 !
set var=!var:u=21 !
set var=!var:v=22 !
set var=!var:w=23 !
set var=!var:x=24 !
set var=!var:y=25 !
set var=!var:z=26 !
echo !var!
)
echo !var! > !name!.txt
pause >nul
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:END
cls
title SHUTTING DOWN...
echo.
echo.
echo.
echo Terminating service stream...
echo.
echo.
echo.
echo.
echo Done! Thank you for using this program!
TIMEOUT /t 5 /nobreak > nul
::(%xx%) -1 I/O Stream= "SHELL.dll"
:: IF EXIST [&1[Parser_2009]] exit
Exit
:: #####################################################################################
You've got a few problems. First, the access denied problem is from you redirecting to a hidden file.
echo %name% > Language_File.txt
attrib +h Language_File.txt
Note that the first time you run the script, it will work because Language_File.txt won't exist and therefore won't be hidden. The second time you run it, you'll get access denied. I don't know why Windows doesn't let you do that. You can solve this problem in a couple ways.
1. Save your file to the user's temp directory. With this approach your directory won't get cluttered.
echo %name% > %TMP%\Language_File.txt
2. Save your file to a subdirectory that you own so that it doesn't clutter the script's directory.
if not exist workspace mkdir workspace
echo %name% > workspace\Language_File.txt
3. Unhide the file before you use it. Since the file may not exist the first time you run the script, perhaps you should only attrib -h if it exists.
if exist Language_File.txt attrib -h Language_File.txt
echo %name% > %TMP%\Language_File.txt
attrib +h Language_File.txt
4. Don't use Language_File.txt at all! I don't see why you need it. Just use variables to hold the name of the language file. In fact, you already have the name in %name%, right?
Second, you should check the value of your variables to see what they really hold. When you load the contents of Language_File.txt into your variable, it's loading all the contents. That includes the hidden newline characters \r\n, although the script seems to bring them into the variable as spaces. See:
c:\batch\t>echo language file is loading now!
language file is loading now
C:\batch\t>set /p name= <Language_File.txt
C:\batch\t>echo -%name%-
-langfile -
If you echo %name% surrounded by hyphens, you can see that there are 2 spaces after it from (presumably) the newline characters. To solve this problem, you can use set to trim the trailing characters.
C:\batch\t>echo language file is loading now!
language file is loading now
C:\batch\t>set /p name= <Language_File.txt
C:\batch\t>set name=%name:~0,-2%
C:\batch\t>echo -%name%-
-langfile-
In the second example, `%name% doesn't have the hidden characters.
Finally, you only need to use ! to access variables that you set inside the for loop. So all references to !name! should be %name% instead. That's probably your "cannot find file" error.
heres the "stringparsing.bat" file:
#echo off
setlocal enabledelayedexpansion
title BETA
cls
cd C:\script\st
echo.
echo.
echo.
echo Setting Variables...
echo Loading Language Database...
:: ###################################################################################
:: CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE
:: ###################################################################################
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:MAIN
set foo=0
cls
echo.
echo.
echo.
echo.
echo ===================================
echo #################################
echo ####### Main Menu: #######
echo #################################
echo ===================================
echo.
echo.
echo 1.) Create New Language File...
echo.
echo 2.) Load Existing Lanuage File...
echo.
echo 3.) Settings...
echo ---------------------------------------------------------
SET /p CHOICE= Select a Function:
IF %CHOICE%== 1 GOTO CREATE
IF %CHOICE%== 2 GOTO LOAD
IF %CHOICE%== 3 GOTO SETTINGS
GOTO MAIN
:CREATE
cls
title Step 1
echo.
echo.
echo.
echo =================================================================================
echo.
set /p name= please type a name for your new language file:
echo.
echo =================================================================================
cls
echo. > %name%.txt
echo.
echo.
echo.
echo ==============================================================
echo ##############################################################
echo #============================================================#
echo # #
echo # - After you hit enter you will be redirected #
echo # to a Live Typer. so anything you type into #
echo # it will be sent to %name%.txt. #
echo # #
echo # #
echo # - Next, select load language File For Encoding! #
echo # #
echo #============================================================#
echo ##############################################################
echo ==============================================================
set /p line1= :
echo %line1% >> %name%.txt 2> nul
echo %name% > Language_File.txt
attrib +h Language_File.txt
set /a foo+ =1
)
echo.
echo ==========================================================
goto LOAD
:LOAD
set /a foo+ =1
IF %foo%== 2 goto loadexternal
goto LOAD23
:loadexternal
echo.
echo language file is loading now!
set /p name=<Language_File.txt
timeout /t 4 /nobreak > nul
echo.
echo.
echo Language_File Loaded!
pause >nul
goto LOAD23
:LOAD23
cls
echo.
echo.
echo.
echo.
echo.
echo Encoding Your Language File... Please Wait...
echo.
echo.
echo.
for /f "delims=" %%i in (!name!.txt) do (
echo translating "%%i"
set var=%%i
set var=!var:a=1 !
set var=!var:b=2 !
set var=!var:c=3 !
set var=!var:d=4 !
set var=!var:e=5 !
set var=!var:f=6 !
set var=!var:g=7 !
set var=!var:h=8 !
set var=!var:i=9 !
set var=!var:j=10 !
set var=!var:k=11 !
set var=!var:l=12 !
set var=!var:m=13 !
set var=!var:n=14 !
set var=!var:o=15 !
set var=!var:p=16 !
set var=!var:q=17 !
set var=!var:r=18 !
set var=!var:s=19 !
set var=!var:t=20 !
set var=!var:u=21 !
set var=!var:v=22 !
set var=!var:w=23 !
set var=!var:x=24 !
set var=!var:y=25 !
set var=!var:z=26 !
echo !var!
)
echo !var! > !name!.txt
pause >nul
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:END
cls
title SHUTTING DOWN...
echo.
echo.
echo.
echo Terminating service stream...
echo.
echo.
echo.
echo.
echo Done! Thank you for using this program!
TIMEOUT /t 5 /nobreak > nul
::(%xx%) -1 I/O Stream= "SHELL.dll"
:: IF EXIST [&1[Parser_2009]] exit
Exit
:: #####################################################################################
I Finally learned how to format the code snippet.
(heres a link to another copy of it if you need it.)
how to replace a string on the second line in a text file using a batch file?

Resources