Reputation: 27
So I have created a file that works and when testing it without the if/else statement. When I put in this in a if statement it doesn't work at all though, is my syntax wrong or what? Thanks.
@echo off
set /p id= Folder Name:
set /p yn= Subfolders? (y/n):
If %yn% == "y"
Set rootDirectory = Y:\
md %id
Set rootDirectory = Y:\%id%
md %id%\Source
md %id%\Work
md %id%\PrintFinal
%SystemRoot%\explorer.exe %id%
Else
Set rootDirectory = Y:\
md %id%
%SystemRoot%\explorer.exe %id%
Upvotes: 1
Views: 71
Reputation: 13922
You need to enclose the blocks of code within parenthesis.
@echo off
set /p id= Folder Name:
set /p yn= Subfolders? (y/n):
If %yn% == "y" (
Set rootDirectory = Y:\
md %id%
Set rootDirectory = Y:\%id%
md %id%\Source
md %id%\Work
md %id%\PrintFinal
) else (
Set rootDirectory = Y:\
md %id%
)
%SystemRoot%\explorer.exe %id%
Upvotes: 1
Reputation: 1047
Here's an updated one
@echo off
set /p id= Folder Name:
set /p yn= Subfolders? (y/n):
If %yn% == y
Set rootDirectory = Y:\
md %id
it works for me
Upvotes: -1
Reputation: 10973
You forgot to add (
and )
to group statements.
Call IF /?
and you will get a help page which describes the syntax of the IF statement
Upvotes: 1