I always get the README file in cmd rather than commands if I type commands - windows

I am trying to make a program in Windows, and whenever you type "commands" or anything else, it always shows you the README file. Nothing else.
I have tried adding quotes to the commands in the cmd file, but that still didn't work. I'm using Windows 8.1 x64.
Prototype.cmd:
#echo off
set version=1.0.0 ALPHA
title Prototype version %version%
echo Welcome to Prototype!
echo You have to change the User Directory in the command file to your username.
timeout 1 > NUL
IF NOT EXIST C:\Users\OldBo-5\Desktop\Prototype\System GOTO SYSTEMNOTFOUND
timeout 5 > NUL
cls
:PrototypeMain
echo Type "commands" to get a list of commands.
echo Type "README" to get the readme text file.
timeout 1 > NUL
set /p cmd=">"
cd C:\Users\OldBo-5\Desktop\Prototype\System\Commands
if %cmd% == "readme" goto :ReadmeCmd
:ReadmeCmd
notepad C:\Users\OldBo-5\Desktop\Prototype\READ ME.text
cls
goto PrototypeMain
if %cmd% == "commands" goto :HelpCmd
:HelpCmd
cls
echo "COMMANDS" - Shows this.
echo "README" - Shows readme.text
timeout 10 > NUL
goto PrototypeMain
:SYSTEMNOTFOUND
cls
title Error starting Prototype.
echo Error starting Prototype. Error Code: 4 - System directory not found. Output error log to ROOT\ErrorLog.text
echo Did you forget to install?
echo To open, right click and click Edit. Select Notepad.
cd C:\Users\OldBo-5\Desktop\Prototype\
type NUL > ErrorLog.text
echo Prototype failed to boot. Error Code: 4 > ErrorLog.text
echo Reason: Error Code 4 means that the system directory could not be found. >> ErrorLog.text
timeout 5 > NUL
exit

Does this help you?
#Echo Off
Set "version=1.0.0 ALPHA"
Title Prototype version %version%
CD /D "%UserProfile%\Desktop\Prototype" 2>NUL||Exit /B
Echo Welcome to Prototype!
Timeout 1 >NUL
If Not Exist "System\" GoTo SYSTEMNOTFOUND
:PrototypeMain
ClS
Set "cmnd="
Echo To get a list of commands type COMMANDS
Echo To get the ReadMe text file type README
Set /P "cmnd=>"
If /I "%cmnd%" == "readme" (
Notepad "READ ME.text"
) Else If /I "%cmnd%" == "commands" (
ClS
Echo COMMANDS - Shows this.
Echo README - Shows readme.text
Timeout 10 >NUL
)
GoTo PrototypeMain
:SYSTEMNOTFOUND
ClS
Title Error starting Prototype.
Echo Error starting Prototype. Error Code: 4 - System directory not found. Output error log to ErrorLog.text
Echo Did you forget to install?
( Echo Prototype failed to boot. Error Code: 4
Echo Reason: Error Code 4 means that the system directory could not be found.
)>"ErrorLog.text"
Timeout 5 >NUL
Exit /B

Related

Window batch commands to detect if downloaded file exists?

I use a windows batch file that scans download folder and if it detects label.pdf it sends to local printer. This works fine most of the time but often it detects file before the file completely downloads which causes PDFtoPrinter error. Is there a way to make sure the download process is complete before attempting to detect?
#echo off
cls
:start
IF EXIST "C:\Users\Downloads\label.pdf" (
echo "Found!"
ping 127.0.0.1 -n 1 -w 3000> nul
"C:\Users\Downloads\PDFtoPrinter" label.pdf "4BARCODE 4B-2054A"
ping 127.0.0.1 -n 1 -w 10000> nul
del "C:\Users\Downloads\label.pdf"
) ELSE (
echo "it isn't here!"
)
goto start
You can use the mechanism to check if a file is locked for exclusive access by another application.
#echo off
cls
:start
IF EXIST "C:\Users\Downloads\label.pdf" (
REM check if file is locked
2>nul (>>"C:\Users\Downloads\label.pdf" (call )) && ("C:\Users\Downloads\PDFtoPrinter" label.pdf "4BARCODE 4B-2054A") || (echo file is locked)
) ELSE (
echo "it isn't here!"
)
Timeout /T 10
goto start

=y was unexpected at this time

I'm trying to make a script to autoinstall packages on Windows, and I keep getting
=y was unexpected at this time
What's wrong with it?
#echo off
echo Checking Internet...
Ping www.google.com -n 1 -w 1000
cls
if errorlevel 1 (set internet=n) else (set internet=y)
if %internet%=y goto start
if %internet%=n goto warn
:warn
echo Warning! You are not connected to the Internet.
echo Chocolatey will not install until you connect and
echo run this batchfile again.
echo Press any key to continue anyways.
pause >nul
:start
echo Copying...
echo [sudo.exe]
mkdir C:\pkg
copy sudo.exe C:\pkg
sudo xcopy C:\pkg\sudo.exe C:\Windows
echo [chocolatey.bat]
copy chocolatey.bat C:\pkg
echo [package.bat]
copy package.bat C:\pkg
echo Installing Choco...
if %internet%=y sudo C:\pkg\chocolatey.bat
if %internet%=n echo Cancelled: No internet.
echo Press any key when complete.
pause >nul
echo Installing Packages...
if %internet%=y sudo C:\pkg\package.bat
if %internet%=n echo Cancelled: No internet.
echo Press any key when complete
Note: I use "sudo.exe" to elevate privileges. I'm not trying to use bash in windows.
I keep getting "=y was unexpected at this time" What's wrong with it?
if %internet%=y goto start
= is not a valid comparison operator, you should be using ==:
if %internet%==y goto start
That applies to all of your if %internet% commands.
Syntax
F:\test>if /?
Performs conditional processing in batch programs.
IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
NOT Specifies that Windows should carry out
the command only if the condition is false.
ERRORLEVEL number Specifies a true condition if the last program run
returned an exit code equal to or greater than the number
specified.
string1==string2 Specifies a true condition if the specified text strings
match.
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
if - Conditionally perform a command.
You can do something like this :
#echo off
echo Checking Internet...
Ping www.stackoverflow.com -n 1 -w 1000
cls
if "%errorlevel%" EQU "1" (set internet=N) else (set internet=Y)
if /I "%internet%"=="y" goto start
if /I "%internet%"=="n" goto warn
:start
echo start
pause
Exit /b
:warn
echo warn
pause
Exit /b

Issue concerning path input in .bat menu

Hi I am trying to make a small menu in which the .bat file uses the user input to define a path. The code below works.
#ECHO OFF
SET /P var= Type The FULL Path In Here:
MKDIR %var%\
pause
However when I try to implement the code into the menu below. It fails and I can't read the error because it immediately exits the batch file. I am running a windows 10 machine and running the batch from the C:\ drive. The batch file makes the folders on the C:\ drive as well. I would be grateful for any help Thanks.
ECHO OFF
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PRESS 1 to select your task, or 2 TO EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Set Path
ECHO.
ECHO 2 - EXIT
ECHO.
SET /P M=Type 1 or 5 then press ENTER:
IF %M%==1 GOTO CallScript1
IF %M%==5 GOTO EOF
CallScript1
#ECHO OFF
SET /P var= Type The FULL Path In Here:
MKDIR %var%\
GOTO:EOF
You are missing the colon before the label CallScript1 on line 17
i.e. replace
CallScript1
with
:CallScript1

Check for a File Periodically in a MS DOS Batch File

I'm writing an MS DOS batch file that looks for a specific file until it is found.
My code gives me the following error after the SET commands
The syntax of the command is incorrect
C:\> If not exist d:\fdev\data\filename.csv
Here's the code:
SET driveltr=d:\
SET envdir=fdev\
SET datadir=data\
SET archivedir=archive\
SET inputdir=c:\Epic\v8.2\Analytics Tools\Epic BI\Input
SET filename=filename.csv
:while1
if not exist %driveltr%%envdir%%datadir%%filename%
(
echo "Waiting to check for file"
ping -n 11 127.0.0.1 > nul
goto :while1
)
You need "" If your path contains spaces. wait till file exists is working this way:
:while
IF EXIST proceed.txt goto :break
echo "Waiting to check for file"
ping -n 11 127.0.0.1 > nul
goto :while
:break

BATCH- How to put a variable into the move command?

Okay, this is my first question on Stackoverflow, so I'll try to make it a good one.
I've searched all over the web and I couldn't find any information to this. I have created a little batch file that prompts you to put in the name of a file that you would like to move. After that, it asks your your usersname. The problem I'm having is cmd tells me I have incorrect syntax.
Can anyone see what I did wrong?
Below is the code I am using. I just pasted in the part that is having trouble.
Thanks guys!
echo Place the file you wish to move to the Windows Startup Folder on your desktop.
echo When you have placed it there, type in the name of your file, NOT INCLUDING the extension.
echo Example: The file's name is: myfile.bat You type in: myfile
set/p "filename=>"
echo %filename%
echo Next, type in your username.
echo Example: acly6
set/p "USERNAME=>"
echo %USERNAME%
ping 192.2.0.0 -n 1 -w 500 > nul
goto MOVE
:MOVE
echo Moving your file to your startup folder.
move C:\Users\%USERNAME%\Desktop\%filename%.bat
C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\
ping 192.2.0.0 -n 1 -w 1000 > nul
echo Checking Volumes...
ping 192.2.0.0 -n 1 -w 3000 > nul
if EXIST C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\StartMenu\Programs\Startup\%filename%goto COMPLETED
goto FAILED
I editted a bit your script:
Surrounded filepaths with double quotes
Added /y parameter to move command to override automatically the file in new location (if exists)
Spotted some issues:
goto MOVE
:MOVE has no sense as it will continue anyway that path.
goto FAILED GOTO COMPLETED - there're no such labels in your script.
Please shout if you have other problems.
#echo off
echo Place the file you wish to move to the Windows Startup Folder on your desktop.
echo When you have placed it there, type in the name of your file, NOT INCLUDING the extension.
echo Example: The file's name is: myfile.bat You type in: myfile
set/p "filename=>"
echo %filename% echo Next, type in your username.
echo Example: acly6
set/p "USERNAME=>"
echo %USERNAME%
ping 192.2.0.0 -n 1 -w 500 > nul
goto MOVE
:MOVE
echo Moving your file to your startup folder.
move /Y "C:\Users\%USERNAME%\Desktop\%filename%.bat" "C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
ping 192.2.0.0 -n 1 -w 1000 > nul
echo Checking Volumes...
ping 192.2.0.0 -n 1 -w 3000 > nul
if EXIST "C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\%filename%" goto COMPLETED
goto FAILED
:FAILED

Resources