I'm writing a small folder locking software. Recently a masking function was integrated, so that the password input is masked. When in a bat file the program works perfectly, however after compiling the program stops working. The problem ,I think, lies in the "masking" code, as it starts an endless loop and masks every input, even the "Enter" stroke, thus preventing the program from further executing. I even tried iexpress, but it also gives an Error, namely:
Error creating process Command.com/c
C:\Users...\AppData\Local\Temp\IXP000.TMP\Folder~1.BAT
Can someone please double check my code and tell me what is wrong, as I am still learning and could not figure out how to fix it.
Thanks in advance.
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
mode con cols=80 lines=25
color 5F
title Folder Locker by KBKOZLEV
:SETPASS
set "tipp="
set "password="
if exist "password.txt" (
set /p password=<password.txt
attrib +h +s "password.txt"
)
if exist "tipp.txt" (
set /p tipp=<tipp.txt
attrib +h +s "tipp.txt"
)
:START
if exist "Locked" goto :OPEN
if exist "Unlocked" goto :LOCK
if not exist "Unlocked" goto :MDLOCKER
:LOCK
ren "Unlocked" "Locked"
attrib +h +s "Locked"
echo(
echo Folder locked.
CHOICE /C X /T 1 /D X > nul
goto :END
exit
:MDLOCKER
md "Unlocked"
echo>password.txt 1234
echo>tipp.txt 1234
attrib +h +s "password.txt"
attrib +h +s "tipp.txt"
cls
echo(
echo Private folder created successfully.
CHOICE /C X /T 1 /D X > nul
goto :END
:OPEN
color 2F
cls
echo ********************************************************************************
echo Folder Locker by KBKOZLEV v.01
echo.
echo ********************************************************************************
echo ---- Enter password to unlock folder, or enter "new" to set a new password. ----
echo --------------------------------------------------------------------------------
echo.
echo Password tipp: %tipp%
echo(
set "pass="
rem set /p "pass=Password: "
Set /P "=Password:" < Nul
Call :PasswordInput pass
if /i "%pass%"=="new" goto :NEWPASS
if "%pass%"=="%password%" (
attrib -h -s "Locked"
ren "Locked" "Unlocked"
echo(
echo Folder unlocked successfully.
goto :END
)
goto :FAIL
:FAIL
color 4F
cls
echo(
echo Invalid password, please try again.
CHOICE /C X /T 1 /D X > nul
cls
goto :OPEN
:NEWPASS
color 8F
cls
echo(
set "oldpass="
rem set /p "oldpass=Old password: "
Set /P "=Old Password:" < Nul
Call :PasswordInput oldpass
if not "%oldpass%"=="%password%" goto :FAIL
:ENTERNEW
color 8F
cls
echo(
set "newpass=""
rem set /p "newpass=New password: "
Set /P "=New Password:" < Nul
Call :PasswordInput newpass
set newpass=%newpass:"=%
if "%newpass%"=="" (
echo(
echo Invalid new password, please enter new password again.
CHOICE /C X /T 1 /D X > nul
goto :ENTERNEW
)
if exist "password.txt" attrib -h -s "password.txt"
echo>password.txt %newpass%
echo(
set "passtipp=""
set /p "passtipp=New tipp: "
set passtipp=%passtipp:"=%
if exist "tipp.txt" attrib -h -s "tipp.txt"
if not "%passtipp%"=="" (
echo>tipp.txt %passtipp%
) else (
del "tipp.txt"
)
goto :SETPASS
:END
color
EndLocal
Goto :Eof
:PasswordInput
::Author: Carlos Montiers Aguilera
::Last updated: 20150401. Created: 20150401.
::Set in variable Line a input password
::
::Update 20150503: http://stackoverflow.com/users/3439404/josefz?tab=profile
::Changes made in next lines:
:: SetLocal EnableDelayedExpansion
:: If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
::Usage:
:: Call :PasswordInput variableName
::where variableName is a name of output variable (by reference call)
::
SetLocal EnableDelayedExpansion
For /F skip^=1^ delims^=^ eol^= %%# in (
'"Echo(|Replace.exe "%~f0" . /U /W"') Do Set "CR=%%#"
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set "BS=%%#"
Set "Line="
:_PasswordInput_Kbd
Set "CHR=" & For /F skip^=1^ delims^=^ eol^= %%# in (
'Replace.exe "%~f0" . /U /W') Do Set "CHR=%%#"
If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
If !CHR!==!BS! (If Defined Line (Set /P "=!BS! !BS!" <Nul
Set "Line=!Line:~0,-1!"
)
) Else (Set /P "=*" <Nul
If !CHR!==! (Set "Line=!Line!^!"
) Else Set "Line=!Line!!CHR!"
)
Goto :_PasswordInput_Kbd
You are executing the 16 bit command.com (only in Win 32) not the 32 or 64 bit cmd.exe. It doesn't suport brackets, long filenames, or set /p.
It also doesn't support long file names.
Related
I'm making a game in batch, but when i try to write to a file, cmd just crashes. I'm writing to a file to save data. So that the user can just come back and load it up.
Create User Code Block:
:cruser1
cls
set /a created=1
echo(
set /p name=Enter The Name of The User::
goto save
Load User Code Block:
:loaduser
cls
set /a created=0
echo(
set /p loaduser=Enter The Name of The User to Load::
if exist "%loaduser%.dll" (
< %loaduser%.dll (
set /p MHP=
set /p HP=
set /p DMG=
set /p GOLD=
set /p EXP=
set /p LVL=
set /p MEXP=
)
goto menu
)
if not exist "%loaduser%.dll" (
echo File not found.
timeout /t 3 /NOBREAK >nul
goto loaduser
)
Save Data Code Block:
:save
cls
echo(
if %created% equ 1(
(
echo %MHP%
echo %HP%
echo %DMG%
echo %GOLD%
echo %EXP%
echo %LVL%
echo %MEXP%
) > %name%.dll
attrib +h "%name%.dll"
goto menu
)
if %created% equ 0(
(
echo %MHP%
echo %HP%
echo %DMG%
echo %GOLD%
echo %EXP%
echo %LVL%
echo %MEXP%
) > %loaduser%.dll
attrib +h "%loaduser%.dll"
goto menu
)
Does anyone know how to fix this and why it's happening?
Edit: I debugged it, after saving echoing it worked, after i killed the enemy, It did say it worked, but also Access is denied.
Hopefully this helps.
You have errant parentheses, Issue one. issue 2 failure to test existance for existing hidden file
If exist "%loaduser%.dll" attrib -h "%loaduser%.dll"
if %created% equ 0 (
echo %MHP%
echo %HP%
echo %DMG%
echo %GOLD%
echo %EXP%
echo %LVL%
echo %MEXP%
) > %loaduser%.dll
attrib +h "%loaduser%.dll"
goto menu
I have a batch script which is used to change a folder's icon.
If [%1] == [] goto :eof
ECHO [.ShellClassInfo] >%1\desktop.in
ECHO IconResource=Example.ico,0 >>%1\desktop.in
move %1\desktop.in %1\desktop.ini
attrib +S +H %1\desktop.ini
attrib +R %1
The problem is that currently the batch file only accepts one folder dropped onto it.
Is there a way for it to accept multiple dropped folders?
if you drop more than one folder, they are received. %1 is just the first of them. Next would be %2 etc. There is a shift command, which shifts the parameters to the left (%1 is discarded, %2 becomes the new %1 etc.):
#echo off
:loop
if "%~1"=="" pause & goto :eof
echo %~1
shift
goto :loop
Notes: use doublequoutes instead of [ and ] to correctly process folders with spaces (and avoid syntax errors with the if command.
use %~1 to remove any surrounding quotes (will be added automatically, if the folder name contains space(s).
There is a line length limitation of about 8200 chars. If you drop too many folders (exceeding the character limit), it will be cut off.
You can try something like that :
#echo off
Color 0A & Mode 75,3
set "ScriptName=%~nx0"
Title Drag and Drop a folder or multi folders over "%ScriptName%"
if "%~1"=="" goto error
:loop
set "$Folder=" & pushd "%~1" 2>nul && ( popd & set "$Folder=%~1"
) || (
set "$Folder=" && echo "%~1" is not a folder & pause
)
If Defined $Folder Call :WriteDesktopIni %$Folder%
shift
if not "%~1"=="" goto loop
echo(
echo End of the script "%ScriptName%"
Timeout /T 3 /nobreak>nul & Exit
::***************************************************************************
:WriteDesktopIni [Folder]
if exist "%~1\desktop.ini" ( attrib -h -s -a "%~1\desktop.ini" >nul 2>&1 )
(
ECHO [.ShellClassInfo]
ECHO IconResource=%systemroot%\system32\shell32.dll,47
)>"%~1\desktop.ini"
attrib +S +H +A "%~1\desktop.ini"
attrib +R "%~1"
goto :eof
::***************************************************************************
:Error
echo(
echo You should drag and drop a folder or multi folders over "%ScriptName%"
Timeout /T 3 /nobreak>nul & exit
::***************************************************************************
Edit : CustomIconFolder.bat
In this script, you can select a folder or multi folders and your custom icon by drag and drop over the script
#echo off & Setlocal EnableDelayedExpansion
Color 0A & Mode 78,5
set "ScriptName=%~nx0"
set /a "count=0"
Title Drag and Drop a folder or multi folders over "%ScriptName%"
if "%~1"=="" goto error
for %%a in (%*) do (
set /a "count+=1"
set "$Folder=" & pushd "%%~a" 2>nul && ( popd & set "$Folder[!count!]=%%~a"
) || (
set "$Folder="
Setlocal DisableDelayedExpansion
color 0C & echo(
echo "%%~a"
echo ====^> is not a folder !
echo Exiting the script . . .
endlocal
Timeout /T 3 /nobreak>nul & exit
)
)
Rem Dispaly selected folders
Mode 75,10
Setlocal EnableDelayedExpansion
for /L %%i in (1,1,%count%) do (
If [%count%] EQU [1] (
echo You have chosen this folder :
echo [%%i] - "!$Folder[%%i]!"
) else (
echo [%%i] - "!$Folder[%%i]!"
)
)
Timeout /T 2 /nobreak>nul
Mode 78,8 & Cls & echo(
echo Please drag and drop your custom icon to be set to your folder over here
echo and press enter...
echo(
echo Or just write the whole path and press enter ...
Set /p "Icon="
If [!Icon!] EQU [] (
cls & echo(
echo The selected icon is : "%systemroot%\system32\shell32.dll,47"
Timeout /T 3 /nobreak>nul
for /L %%i in (1,1,%count%) do (
echo !$Folder[%%i]!
Call :WriteDesktopIni !$Folder[%%i]! "%systemroot%\system32\shell32.dll,47"
)
) Else (
for %%a in (!Icon!) do ( set "Icon_Name=%%~nxa" & set "Ext=%%~xa" )
If /I [!Ext!] EQU [.ICO] (
cls & echo(
echo The selected icon is : "!Icon_Name!"
echo From this path : !Icon!
Timeout /T 3 /nobreak>nul
for /L %%i in (1,1,%count%) do (
echo "!$Folder[%%i]!"
Copy /y !Icon! "!$Folder[%%i]!\!Icon_Name!">nul 2>&1
Attrib +H "!$Folder[%%i]!\!Icon_Name!">nul 2>&1
Call :WriteDesktopIni !$Folder[%%i]! "!Icon_Name!"
)
) else (
Cls & Color 0C & echo(
echo The extension : [*!Ext!] is not allowed
Timeout /T 3 /nobreak>nul
)
)
cls
echo(
echo End of the script "%ScriptName%"
Timeout /T 2 /nobreak>nul & Exit
::***************************************************************************
:WriteDesktopIni [Folder] [Icon]
if exist "%~1\desktop.ini" ( attrib -h -s -a "%~1\desktop.ini" >nul 2>&1 )
(
ECHO [.ShellClassInfo]
ECHO IconResource=%~2
)>"%~1\desktop.ini"
attrib +S +H +A "%~1\desktop.ini">nul 2>&1
attrib +R %~1>nul 2>&1
goto :eof
::***************************************************************************
:Error
Mode 86,10 & color 0B
echo( & echo(
echo You should drag and drop a folder or multi folders over "%ScriptName%"
echo(
echo Or Usage in command line like this syntax :
echo(
echo %~nx0 "FolderPath1" "FolderPath2" "FolderPath3" "FolderPath4"
Timeout /T 10 /nobreak>nul & exit
::***************************************************************************
When i use it, it will only speak when i teach it another word, i can't get it to speak a specific answer in the directory, do you guys have any opinions on how to go about fixing this, i'm stumped..
#ECHO OFF
#mode con cols=55 lines=10
if not exist data.txt echo.>data.txt
:begin
set /p text="Talk: "
for /f "tokens=1,* delims=#" %%i in (data.txt) do (
if /i "%text%"=="%%i" (
echo Visu: %%j
goto begin
)
)
:Learn
echo --- I don't know that.
set /p answer=--- What would be a good answer to '%text%'?
echo %text%#%answer%>>data.txt
echo Visu: thank you
goto Aye
:Aye
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp.vbs"
echo speech.speak "%answer%" >> "temp.vbs"
start temp.vbs
pause
del temp.vbs
goto begin
Make Aye a subroutine/function you can call with the text to speak.
In a called sub the first argument is %1
#ECHO OFF
mode con cols=55 lines=10
if not exist data.txt Type Nul >data.txt
:begin
cls& Echo Talk to Visu
set "text=" & set /p text="Talk: "
if not defined text exit /B
for /f "tokens=1,* delims=#" %%i in (data.txt
) do if /i "%text%"=="%%i" Call :Aye "%%~j" & Goto :begin
:Learn
echo --- I don't know that.
echo --- What would be a good answer to '%text%'
set /p answer=?
echo %text%#%answer%>>data.txt
Call :Aye "%answer%"
goto :begin
:Aye
echo Visu: %~1
echo Visu: thank you
echo set speech = Wscript.CreateObject("SAPI.spVoice") > "temp.vbs"
echo speech.speak "%~1" >> "temp.vbs"
cscript //Nologo temp.vbs
Timeout /T 3 /Nobreak >Nul
del temp.vbs
goto :Eof
replace start temp.vbs with cscript /nologo temp.vbs.
And probably you want
echo set speech = Wscript.CreateObject("SAPI.spVoice") > "temp.vbs"
(> instead of >>) to overwrite the file every time?
I have the following script but I want to map the numbers to the variable but do not know how to. So if a user enters 0, I want it to search for the event name NewUser.
#echo off
mode con:cols=40 lines=40
set /p customerID="Enter Customer ID: "
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PLEASE SELECT THE EVENT FROM THE MENU BELOW
ECHO ...............................................
ECHO.
ECHO Event Code Event Name
ECHO.
ECHO 0 NewUser
ECHO 1 ExistingUser
ECHO 2 EmailAdded
ECHO 3 AccountProblem
ECHO 4 Lost
ECHO.
SET /P event=Type the event code and then press ENTER:
IF %event%==0 set event=NewUser GOTO find
IF %M%==1 set event=ExistingUser GOTO find
IF %M%==2 set event=EmailAdded GOTO find
IF %M%==3 set event=AccountProblem GOTO find
IF %M%==4 set event=Lost GOTO find
pause
:find
pause
setlocal enableextensions disabledelayedexpansion
pause
set "sourceFolder=C:\test"
set "targetFolder=C:\test2"
pause
set "customerID=%customerID%"
set "NewUser=%Event%"
pause
for /f "delims=" %%a in ('
findstr /m /s /l /c:"%customerID%" "%sourceFolder%\*"
^| findstr /f:/ /m /l /c:"%event%"
') do (
copy "%%~fa" "%targetFolder%"
)
pause
The first version of your code was closer to correct solution than current one; you need to use two nested for /F loops as follows:
for /f "delims=" %%a in ('
findstr /I /m /s /l /c:"%customerID%" "%sourceFolder%\*.txt"
') do for /f "delims=" %%A in ('
findstr /I /m /l /c:"%event%" "%%~fa"
') do (
rem 'copy' command is merely displayed using ECHO for debugging purposes
ECHO copy "%%~fa" "%targetFolder%"
)
Next commented code snippet could help to improve the script:
#ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
set "customerID="
:customerID
set /p customerID="Enter Customer ID: "
if not defined customerID goto :customerID
REM instead of above test, you could apply next statement about `set /P`:
REM If the user does not enter anything (just presses return)
REM then the variable will be unchanged and an ERRORLEVEL will be set.
rem CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PLEASE SELECT THE EVENT FROM THE MENU BELOW
ECHO ...............................................
ECHO.
ECHO Event Code Event Name
ECHO.
ECHO 0 NewUser
ECHO 1 ExistingUser
ECHO 2 EmailAdded
ECHO 3 AccountProblem
ECHO 4 Lost
ECHO.
REM SET /P M=Type the event code and then press ENTER:
choice /C 01234 /M "Type the event code"
REM 0 means that an user's reply to "Terminate batch job (Y/N)?" was not "y"
IF %ERRORLEVEL% EQU 0 echo "Ctrl-C" or "Ctrl-Break" pressed&goto :NoSearch
REM 255 means another error
IF ERRORLEVEL 255 goto :MENU
REM ERRORLEVEL number Specifies a true condition if the last program run
REM returned an exit code EQUAL TO OR GREATER THAN the number
REM specified.
IF ERRORLEVEL 1 set "event=NewUser"
IF ERRORLEVEL 2 set "event=ExistingUser"
IF ERRORLEVEL 3 set "event=EmailAdded"
IF ERRORLEVEL 4 set "event=AccountProblem"
IF ERRORLEVEL 5 set "event=Lost"
REM Note that in above code, ERRORLEVEL parameters are tested in INCREASING order
REM Used only in this special case
REM (no need of GOTO statement, 'event' variable is set correctly)
REM
REM although CHOICE /? says:
REM When you use ERRORLEVEL parameters in a batch program,
REM list them in decreasing order.
:NOTE
set "sourceFolder=D:\test"
set "targetFolder=D:\test2"
rem ??? set "customerID=%customerID%"
rem ??? set "event=%event%"
rem debugging output
echo looking for "customerID=%customerID%" "event=%event%"
for /f "delims=" %%a in ('
findstr /I /m /s /l /c:"%customerID%" "%sourceFolder%\*.txt"
') do for /f "delims=" %%A in ('
findstr /I /m /l /c:"%event%" "%%~fa"
') do (
rem 'copy' command is merely displayed using ECHO for debugging purposes
ECHO copy "%%~fa" "%targetFolder%"
)
:NoSearch
pause
Change your For loop like this and retest:
FOR /F "DELIMS=" %%A IN (
'FINDSTR/MSC:"%customerID%" "%sourceFolder%\*"^|FINDSTR/MIF:/ /C:"%event%"'
) DO COPY "%%A" "%targetFolder%"
EDIT
I have added a modified version of your script to include the new requirement of a three digit event code. Just adjust it's value in the script as necessary, (lines nineteen to twenty three).
#ECHO OFF
MODE CON:COLS=52 LINES=40
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
(SET sourceFolder=C:\test)
(SET targetFolder=C:\test2)
SET /P "customerID=Enter Customer ID: "
:MENU
CLS
ECHO=
ECHO= ..................................................
ECHO= PLEASE SELECT THE OPTION FROM THE EVENT MENU BELOW
ECHO= ..................................................
ECHO=
ECHO= Option Event Name Event Code
ECHO=
ECHO. 1. NewUser A00
ECHO. 2. ExistingUser A01
ECHO. 3. EmailAdded A02
ECHO. 4. AccountProblem A03
ECHO. 5. Lost A04
ECHO=
CHOICE /C 12345 /M "CHOOSE AN OPTION"
SET "Option=%ERRORLEVEL%"
FOR /F "TOKENS=1-4 DELIMS=. " %%A IN ('FINDSTR/BC:"ECHO. " "%~f0"'
) DO IF "%%B"=="%Option%" (SET "Name=%%C" & SET "Code=%%D")
FOR /F "DELIMS=" %%A IN (
'FINDSTR/MISC:"%customerID%" "%sourceFolder%\*"^|FINDSTR/MIF:/ /C:"%Name%"'
) DO COPY "%%A" "%targetFolder%"
PAUSE
Please make sure that %sourceFolder% is a full path and %targetFolder% already exists, (see line six).
I have a very little problem, which gets on my nerves. I wrote a program for locking folders and I gave it the option to change the password as well as the tipp, however, if no tipp is typed, I want it to just print nothing. Instead it says "echo is off"
I guess it's the syntax, but I do not know where. Can someone double check it for me. thank you!
#Echo Off
setlocal EnableDelayedExpansion
mode con cols=80 lines=25
set /a "tries=3"
color 5F
title Folder Locker by KBKOZLEV
:SETPASS
set "tipp="
set "password="
if exist "password.txt" (
set /p password=<password.txt
attrib +h +s "password.txt"
)
if exist "tipp.txt" (
set /p tipp=<tipp.txt
attrib +h +s "tipp.txt"
)
:START
if exist "Locked" goto :OPEN
if exist "Unlocked" goto :LOCK
if not exist "Unlocked" goto :MDLOCKER
:LOCK
ren "Unlocked" "Locked"
attrib +h +s "Locked"
echo.
echo Folder locked.
CHOICE /C X /T 1 /D X > nul
goto :END
exit
:MDLOCKER
md "Unlocked"
echo>password.txt 1234
echo>tipp.txt 1234
attrib +h +s "password.txt"
attrib +h +s "tipp.txt"
cls
echo.
echo Private folder created successfully.
CHOICE /C X /T 1 /D X > nul
goto :END
:OPEN
color 2F
cls
echo ********************************************************************************
echo Folder Locker by KBKOZLEV v.01
echo.
echo ********************************************************************************
echo ---- Enter password to unlock folder, or enter "new" to set a new password. ----
echo You have %tries% attempts left.
echo --------------------------------------------------------------------------------
echo.
echo Password tipp: %tipp%
echo.
set "pass="
Set /P "=Password:" < Nul
set "psCommand=powershell -Command "$pword = read-host -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set pass=%%p
if /i "%pass%"=="new" goto :NEWPASS
if "%pass%"=="%password%" (
attrib -h -s "Locked"
ren "Locked" "Unlocked"
echo.
echo Folder unlocked successfully.
goto :END
)
set /a tries=%tries -1
if %tries%==0 (
goto :FAIL2
)
goto :FAIL
:FAIL
color 4F
cls
echo.
echo Invalid password, please try again.
CHOICE /C X /T 1 /D X > nul
cls
goto :OPEN
:FAIL2
color 4F
cls
echo.
echo Invalid password, program will now close.
CHOICE /C X /T 2 /D X > nul
cls
goto :END
:NEWPASS
color 8F
cls
echo.
set "oldpass="
Set /P "=Old Password:" < Nul
set "psCommand=powershell -Command "$pword = read-host -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set oldpass=%%p
if not "%oldpass%"=="%password%" goto :FAIL
:ENTERNEW
color 8F
cls
echo.
set "newpass=""
Set /P "=New Password:" < Nul
set "psCommand=powershell -Command "$pword = read-host -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set newpass=%%p
set newpass=%newpass:"=%
if "%newpass%"=="" (
echo.
echo Invalid new password, please enter new password again.
CHOICE /C X /T 1 /D X > nul
goto :ENTERNEW
)
if exist "password.txt" attrib -h -s "password.txt"
echo>password.txt %newpass%
echo.
set "passtipp=""
set /p "passtipp=New tipp:"
set passtipp=%passtipp:"=%
if exist "tipp.txt" attrib -h -s "tipp.txt"
if not "%passtipp%"=="" (
echo>tipp.txt %passtipp%
) else (
del "tipp.txt"
)
goto :SETPASS
:END
color
EndLocal
exit
The only approach:
if "%passtipp%"=="" (echo(>tipp.txt) else (echo>tipp.txt %passtipp%)
Explanation: see all my comments to other answers (for the present), please...
To suppress the "ECHO is off" text when echoing a blank line, change echo to echo. with a trailing dot. Your script already does this for blank lines to the console. The same thing works for redirecting to files.
For example, this line will put "ECHO is off" into tipp.txt if the %passtip% variable is empty:
echo>tipp.txt %passtipp%
This line will cause tipp.txt to be empty:
>tipp.txt echo.%passtipp%
It's usually safe to append all instances of echo with trailing punctuation. The form echo. can be problem if there is a file named "echo" in the path; In that case, a safer alternative is echo(.
The root cause of your issue is that your syntax for redirecting data to a file is wrong. When echo is run by itself, it outputs whether echo is ON or OFF. So when you have lines like echo>password.txt 1234, you are saying "Take the output of echo and redirect it to password.txt 1234".
What you should be doing is echo 1234>password.txt, which will redirect the string 1234 to password.txt.
And then do the same thing for tipp.txt.
Also, I feel the need to point out that the word you're looking for is "tip," not "tipp."