Reputation: 988
I am new to cmd. I have created a file to create folders and sub folders. I have put some timeout
. The first timeout
is working but other time out is not working do not know why. Is it because of changing the path
. I have checked line by line in CMD. In CMD it works fine.
Input:
timeout /t 5
@echo off
set path=C:\Users\bruce\Documents\Project-Gallary
cd %path%
@echo "Welcome master Bruce !"
@echo "Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
echo %PATH%
timeout /t 10
@echo " *** Try not the put space in Folder Name"
set /p ProjectName="What is the project name? "
Output:
C:\Users\bruce\Desktop>timeout /t 5
Waiting for 0 seconds, press a key to continue ...
"Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
C:\Users\bruce\Documents\Project-Gallary
'timeout' is not recognized as an internal or external command,
operable program or batch file.
" *** Try not the put space in Folder Name"
What is the project name?
Upvotes: 1
Views: 2271
Reputation:
Big mistake, you are changing a system variable PATH
System variable path lists all the paths to executables, you changed it by setting set path=C:\Users\bruce\Documents\Project-Gallary
and now your other cmd's are no longer found.
Try this version instead, first close all your cmd.exe
windows to clear all set
commands.
@echo off
set "mypath=C:\Users\bruce\Documents\Project-Gallary"
cd %mypath%
@echo "Welcome master Bruce !"
@echo "Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
echo %PATH%
timeout /t 10
@echo " *** Try not the put space in Folder Name"
set /p ProjectName="What is the project name? "
Edit
Based on @npocmaka's comment. If you actually want to add the path to the system path variable then simply replace the set path
line to:
set "PATH=%PATH%;C:\Users\bruce\Documents\Project-Gallary"
Upvotes: 6
Reputation: 38623
The answer to your question is yes, it is because you have changed, path
.
The environment variable %Path%
contains locations which are searched when a 'pathless' executable file is not located in the current working directory.
The system also holds another variable called %PATHEXT%
which contains a list of executable file extensions which are suffixed to a file name, (in that lists order), if a file without an extension is called and not found.
If you want to see the values of those two variables, open a command prompt and enter, Set Path
.
When your script gets to the second Timeout
command, it searches the current working directory for any file named Timeout
and with any of the extensions listed in %PATHEXT%
. If not found, it would similarly search each of the locations in %Path%
, which in your case would be C:\Users\bruce\Documents\Project-Gallary
; (as timeout
was not found you received the error message)
The Timeout
command is really timeout.exe
which should be located in \Windows\System32
. Had you not changed the %Path%
variable that location, (preceded by the system drive letter), was defined within the value of the %Path%
environment variable and the appropriate executable file found.
Your solutions are therefore to avoid setting variables named %Path%
or %PATHEXT%
unless absolutely necessary, e.g. Set "lPath=C:\Users\bruce\Documents\Project-Gallary"
. You could alternatively ignore that advice and use absolute paths with extensions, e.g. C:\Windows\System32\timeout.exe /t 10
. Finally you could, if the script requires it, integrate a location, (or extension), into those exiting semicolon delimited variable listings, e.g. Set "Path=%Path%;C:\Users\bruce\Documents\Project-Gallary"
.
Upvotes: 1