批处理文件路径变量%PATH%

时间:2013-12-14 22:23:12

标签: batch-file path chat notepad

我一直在为我的学校创建一个聊天室,但是我必须把文件带回家,以便在需要时进行更改,但我的问题是每次将文件从一个系统移动到另一个系统时都必须更改文件路径另一个。所以我想知道如何创建一个适合我的%PATH%

这是我对主文件的完整代码:

你可能已经注意到我是这个

的新手了

注意:此处的所有内容都可以正常使用设置的文件路径,但我希望它在更换计算机时更轻松。

任何事情都可能有所帮助

@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

3 个答案:

答案 0 :(得分:0)

%PATH%是保留的环境变量,在此处记录:http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/path.mspx?mfr=true

出于诊断目的,您可以回显该变量以分析是否具有您希望具有的值:

echo %path%

答案 1 :(得分:0)

在您的代码中,路径在已经分支到菜单后设置。这可能对您有用:

if %c% EQU carrie goto Menu
if %c% EQU dad SET PATH=%PATH%;c:\Users\Dan W Frye\Desktop\(-_-)& goto menu

要将批处理文件放在每个用户的路径上,请使用:

set path=%path%;%PUBLIC%

将批处理文件复制到C:\Users\Public并从那里运行 除非它需要额外的权限,否则它应该从那里为每个用户运行。

答案 2 :(得分:0)

正如@Jermu Virtanen所提到的,%PATH%变量是一个Windows系统设置路径...你不应该使用/更改它,除非你真的知道你在做什么。 因此,不要使用%PATH%,而是使用%PROGPATH%

之类的内容

同样如@foxdrive所述,如果用户输入“dad”,它将在设置路径变量之前转到“menu”。如果您选择“管理员”然后选择“列出用户”,它将再次调用路径而不先设置它。

您可以通过抓取计算机的域名%userdomain%和当前用户%username%来自动执行某些登录或路径设置。

即;

SET "progpath=c:\Users\%username%\Desktop\(-_-)"