Reputation: 21
Here is my wip program
@ECHO OFF
COLOR 0B
:JRNLMENU
CLS
ECHO WHAT WOULD YOU LIKE TO DO?
ECHO.
ECHO.
ECHO 1-CREATE NEW ENTRY
ECHO 2-READ OLD ENTRIES
ECHO 3-EXIT
SET/P "CHO=>"
IF %CHO%==1 GOTO TESTFOR
IF %CHO%==2 GOTO VIEWENTRY
IF %CHO%==3 GOTO EXIT
ECHO ERROR, PLEASE TRY AGAIN
PAUSE
CLS
GOTO JRNLMENU
:TESTFOR
CLS
CD C:\USERS\%USERNAME%\DOCUMENTS\
IF EXIST CATSYSTEMS GOTO CREATEJRNL
IF NOT EXIST CATSYSTEMS GOTO CREATEFLDR
:CREATEFLDR
MD c:\USERS\%USERNAME%\DOCUMENTS\CATSYSTEMS
CLS
ECHO HELLO
PAUSE
CLS
GOTO CREATEJRNL
:CREATEJRNL
ECHO TYPE WHAT YOU WOULD LIKE TO PUT IN YOUR JOURNAL
ECHO PRESS ENTER TO GO TO THE NEXT LINE
PAUSE
I cant get it to skip createfldr if the folder is there. It will create it in the right place but it doesnt seem to check if it is there. I have a batch file that locks the folder (as most people have seen) so I think the testfor section should work. Most of the other code I use often though so I am pretty sure all the commands work. Any help would be great :)
Upvotes: 2
Views: 47
Reputation: 49085
I suggest to use following version of your batch file:
@ECHO OFF
COLOR 0B
:JRNLMENU
CLS
ECHO WHAT WOULD YOU LIKE TO DO?
ECHO.
ECHO.
ECHO 1-CREATE NEW ENTRY
ECHO 2-READ OLD ENTRIES
ECHO 3-EXIT
SET /P "CHO=>"
IF %CHO%==1 GOTO TESTFOR
IF %CHO%==2 GOTO VIEWENTRY
IF %CHO%==3 GOTO EXIT
ECHO ERROR, PLEASE TRY AGAIN
PAUSE
GOTO JRNLMENU
:TESTFOR
CLS
CD /D "C:\USERS\%USERNAME%\DOCUMENTS\"
IF EXIST CATSYSTEMS GOTO CREATEJRNL
IF NOT EXIST CATSYSTEMS GOTO CREATEFLDR
:CREATEFLDR
MD "C:\USERS\%USERNAME%\DOCUMENTS\CATSYSTEMS"
CLS
ECHO HELLO
PAUSE
CLS
GOTO CREATEJRNL
:CREATEJRNL
ECHO TYPE WHAT YOU WOULD LIKE TO PUT IN YOUR JOURNAL
ECHO PRESS ENTER TO GO TO THE NEXT LINE
PAUSE
There are some small corrections. The perhaps important ones are:
Command CD
without optional parameter /D
could fail if the current working directory is not on drive C:
. Therefore it is always better to use /D
on changing current working directory if no control on which directory is the working directory (Start In
in shortcut properties) on execution of the batch file.
A user account name can include also a space character, see Microsoft article Creating User and Group Accounts. Therefore it is advisable to include all paths containing %USERNAME%
in double quotes.
Two more hints:
Better would be perhaps also to use %USERPROFILE%
instead of C:\USERS\%USERNAME%
if not all users use Windows Vista and later Windows versions or the user account directory is not on drive C:
.
Run your batch file with @ECHO ON
at top instead of @ECHO OFF
to see what is going on when executing the batch file.
Upvotes: 1
Reputation: 41224
To test for folders on a local filesystem reliably, you need a trailing backslash:
IF EXIST CATSYSTEMS\ GOTO CREATEJRNL
IF NOT EXIST CATSYSTEMS\ GOTO CREATEFLDR
Using double quotes allows you to use short or long names:
IF EXIST "CATSYSTEMS\" GOTO CREATEJRNL
IF NOT EXIST "CATSYSTEMS\" GOTO CREATEFLDR
Upvotes: 0