Menu

Practice questions: Basics and batch file syntax

Pick an answer and press "Check answer" to see right away whether you got it. If you are unsure, open "Read the article" to review the command and then try again. Questions you answer correctly are remembered in this browser.

47 questions Solved 0 / 47

Calculation (Arithmetic)

Read the article →

Calculation (Arithmetic) — Question 1

Which is the correct way to assign the remainder of 10 divided by 3 to the variable R inside a batch file?

Choose one answer.

  1. set /a R=10 %% 3
  2. set R=10 % 3
  3. set /a R=10 mod 3

Calculation (Arithmetic) — Question 2

What is the value of X after running set /a X=7 / 2?

Choose one answer.

  1. 3 (the fractional part is truncated)
  2. 3.5
  3. 4 (rounded)

Chaining Commands

Read the article →

Chaining Commands — Question 1

Which statement correctly describes command1 & command2?

Choose one answer.

  1. The next command runs even if the previous command fails
  2. The next command runs only if the previous command succeeds
  3. The next command runs only if the previous command fails

Chaining Commands — Question 2

Which is the right way to delete the original file only if the copy succeeds?

Choose one answer.

  1. copy "a.txt" "b.txt" && del "a.txt"
  2. copy "a.txt" "b.txt" & del "a.txt"
  3. copy "a.txt" "b.txt" || del "a.txt"

Chaining Commands — Question 3

What should you watch out for when using A && B || C like an if-else?

Choose one answer.

  1. C also runs if A succeeds and B fails
  2. C runs only when A fails
  3. B and C run at the same time

Character Encoding and Garbled Text

Read the article →

Character Encoding and Garbled Text — Question 1

Which command changes the command prompt’s code page to UTF-8?

Choose one answer.

  1. chcp 65001
  2. chcp 932
  3. chcp utf8

Checking File Existence

Read the article →

Checking File Existence — Question 1

Which command prints a message when the file does not exist?

Choose one answer.

  1. if exist "%file%" echo missing
  2. if not exist "%file%" echo missing
  3. if exists "%file%" echo missing

Checking File Existence — Question 2

Which is the most appropriate way to check only whether a folder exists?

Choose one answer.

  1. if exist "%dir%"
  2. if exist "%dir%\"
  3. if folder "%dir%"

Create a New Folder

Read the article →

Create a New Folder — Question 1

You ran the following command in a folder that contains no files. Select the correct result.

mkdir disposable\first\second

Choose one answer.

  1. The disposable folder is created, with first inside it and second inside that
  2. The disposable folder is created, but an error occurs because first and second do not exist
  3. An error occurs because the disposable folder does not exist

Create Empty File

Read the article →

Create Empty File — Question 1

Which of the following commands creates a sample.txt file that is not 0 bytes in size?

Choose one answer.

  1. copy nul sample.txt
  2. type nul > sample.txt
  3. echo;>sample.txt

Creating Variables

Read the article →

Creating Variables — Question 1

What option do you need to specify to accept user input as a variable?

Choose one answer.

  1. set /I variable_name=prompt_message
  2. set /P variable_name=prompt_message
  3. set /A variable_name=prompt_message

Delayed Expansion

Read the article →

Delayed Expansion — Question 1

Which statement correctly describes when %variable% and !variable! are expanded?

Choose one answer.

  1. %variable% is expanded at parse time, and !variable! is expanded at execution time
  2. %variable% is expanded at parse time, and !variable! is also expanded at parse time
  3. Both %variable% and !variable! are expanded at execution time

Delete Files and Folders

Read the article →

Delete Files and Folders — Question 1

Which command deletes a folder together with the files inside it?

Choose one answer.

  1. del "%USERPROFILE%\Documents\disposable"
  2. rmdir "%USERPROFILE%\Documents\disposable"
  3. rmdir /s "%USERPROFILE%\Documents\disposable"

Delete Files and Folders — Question 2

Which command deletes a single file?

Choose one answer.

  1. del file.txt
  2. rmdir file.txt
  3. mkdir file.txt

ERRORLEVEL — Question 1

Which statement correctly describes the condition of IF ERRORLEVEL N?

Choose one answer.

  1. It is true when ERRORLEVEL is N or greater
  2. It is true when ERRORLEVEL is exactly N
  3. It is true when ERRORLEVEL is N or less

Escaping Special Characters

Read the article →

Escaping Special Characters — Question 1

Which command correctly displays A & B?

Choose one answer.

  1. echo A ^& B
  2. echo A %& B
  3. echo A \& B

Escaping Special Characters — Question 2

How do you write % to display it as a literal character inside a batch file?

Choose one answer.

  1. %%
  2. ^%
  3. \%

Escaping Special Characters — Question 3

Which command is the most appropriate way to safely assign Tom & Jerry to the variable NAME?

Choose one answer.

  1. set "NAME=Tom & Jerry"
  2. set NAME=Tom & Jerry
  3. set NAME=Tom ^^& Jerry

Getting Date and Time

Read the article →

Getting Date and Time — Question 1

Which statement about the %DATE% environment variable is correct?

Choose one answer.

  1. The format may differ depending on the Windows regional settings
  2. The same YYYY/MM/DD format is guaranteed on every Windows environment
  3. %DATE% returns the UTC date

Help (HELP and /?)

Read the article →

Help (HELP and /?) — Question 1

Which command correctly shows how to use the xcopy command?

Choose one answer.

  1. xcopy /?
  2. xcopy ?
  3. xcopy \?

Help (HELP and /?) — Question 2

In help syntax, what does an item enclosed in [ ], such as [/B], mean?

Choose one answer.

  1. An optional item
  2. A required item
  3. An item that requires administrator rights

Help (HELP and /?) — Question 3

Which command displays long help one screen at a time?

Choose one answer.

  1. for /? | more
  2. for /? > more
  3. more | for /?

How to Create a Batch File

Read the article →

How to Create a Batch File — Question 1

What is the effect of @echo off at the top of a batch file?

Choose one answer.

  1. Runs the batch file with administrator rights
  2. Hides the results of the commands
  3. Stops the commands themselves from being displayed
  4. Sets the encoding of the batch file to UTF-8

How to Create a Batch File — Question 2

Why do you wrap the file name in double quotes, as in "hello.bat", mainly when saving a batch file in Notepad?

Choose one answer.

  1. To save the file with administrator rights
  2. To prevent a .txt extension from being added automatically
  3. To save file names with non-ASCII characters correctly
  4. To make the file smaller

How to Create a Batch File — Question 3

If non-ASCII text such as Japanese is garbled in a batch file, what is the most basic fix?

Choose one answer.

  1. Save the batch file as UTF-8 with BOM
  2. Delete @echo off
  3. Save the file with the ANSI encoding
  4. Move the pause command to the top

Launching Command Prompt

Read the article →

Launching Command Prompt — Question 1

Select the method that is NOT a correct way to launch Command Prompt.

Choose one answer.

  1. Launch using the Start menu search function
  2. Launch directly from "All apps" in the Start menu
  3. Launch from the "Run" dialog

Move to a Different Directory

Read the article →

Move to a Different Directory — Question 1

Which command moves report.txt to the D:\Archive folder?

Choose one answer.

  1. move report.txt D:\Archive\
  2. copy report.txt D:\Archive\
  3. rename report.txt D:\Archive\

Passing Arguments to Batch Files

Read the article →

Passing Arguments to Batch Files — Question 1

Select the appropriate way to pass arguments when calling a batch file from Command Prompt.

Choose one answer.

  1. Set %1, %2... with the set command, then run the call or start command
  2. Create a text file containing the arguments and drag and drop it onto the batch file
  3. When calling the batch file with call or start, write the arguments separated by spaces

Passing Arguments to Batch Files — Question 2

Which of the following is the correct way to pass multiple numbers as arguments?

Choose one answer.

  1. call C:\test\test.cmd 1000 2000 3000
  2. call C:\test\test.cmd (1000 2000 3000)
  3. call C:\test\test.cmd {1000 2000 3000}

Persistent Environment Variables and PATH

Read the article →

Persistent Environment Variables and PATH — Question 1

When you set an environment variable with the setx command, when can that variable be used in the current Command Prompt session?

Choose one answer.

  1. It can be used immediately after running setx
  2. It can be used after opening a new Command Prompt
  3. It can be used only after restarting Windows

Pipes and Filters

Read the article →

Pipes and Filters — Question 1

Which statement correctly describes the pipe in command1 | command2?

Choose one answer.

  1. The standard output of command1 is passed as the standard input of command2
  2. command1 finishes completely before command2 starts
  3. The output of command1 is saved to a file

Reading User Input

Read the article →

Reading User Input — Question 1

What happens to the variable when the user presses only Enter at a set /p prompt?

Choose one answer.

  1. The variable becomes empty
  2. The variable keeps its previous value
  3. An error occurs and the batch file ends

Reading User Input — Question 2

Which is best when you want the user to choose by pressing a single key, y or n, without pressing Enter?

Choose one answer.

  1. Use set /p "key="
  2. Use the choice command
  3. Use the pause command

Redirection — Question 1

Which command correctly saves the output of dir to filelist.txt by overwriting?

Choose one answer.

  1. dir > filelist.txt
  2. dir >> filelist.txt
  3. dir < filelist.txt

Redirection — Question 2

Which operator redirects standard error output to a file?

Choose one answer.

  1. 2>
  2. >>
  3. >

Redirection — Question 3

Which command correctly saves both standard output and standard error to the same file?

Choose one answer.

  1. command > file.txt 2>&1
  2. command >> file.txt
  3. command 2> file.txt

Renaming Files

Read the article →

Renaming Files — Question 1

Which of the following commands renames old.txt to new.txt?

Choose one answer.

  1. rem old.txt new.txt
  2. ren old.txt new.txt
  3. replace old.txt new.txt

Run PowerShell from Command Prompt

Read the article →

Run PowerShell from Command Prompt — Question 1

Which of the following is an appropriate way to run a .ps1 file while avoiding an execution policy error?

Choose one answer.

  1. powershell -NoProfile -ExecutionPolicy Bypass -File .\a.ps1
  2. powershell -NoProfile -Command Bypass .\a.ps1
  3. powershell -NoExit -File

Run PowerShell from Command Prompt — Question 2

How should you write a % that you want included in the string passed to -Command inside a batch file?

Choose one answer.

  1. Write \%
  2. Write %%
  3. Write ^%

Searching for Files

Read the article →

Searching for Files — Question 1

Which command lists only the full paths of files with the .csv extension under C:\work, including subfolders?

Choose one answer.

  1. dir "C:\work\*.csv"
  2. dir /s /b "C:\work\*.csv"
  3. findstr /s ".csv" "C:\work"

Searching for Files — Question 2

Which command shows only the names of text files under the current folder that contain “error”, ignoring case?

Choose one answer.

  1. dir /s /b error*.txt
  2. findstr /s /i /m "error" *.txt
  3. where /R . error

String Operations

Read the article →

String Operations — Question 1

Which syntax extracts the first 5 characters of the string stored in the variable TEXT?

Choose one answer.

  1. %TEXT:~0,5%
  2. %TEXT:~1,5%
  3. %TEXT:~5%

Subroutines and Return Values

Read the article →

Subroutines and Return Values — Question 1

Which technique is used to return a string value from a subroutine?

Choose one answer.

  1. Use a return statement
  2. Run endlocal & set VariableName=Value on one line
  3. Assign directly to a global variable

Tips and Tricks

Read the article →

Tips and Tricks — Question 1

Which key do you press to show the command history list as a popup in the Command Prompt?

Choose one answer.

  1. Press the F7 key
  2. Press the F3 key
  3. Press Ctrl + H

UAC Auto-Elevation

Read the article →

UAC Auto-Elevation — Question 1

After running net session >nul 2>&1, what is the value of ERRORLEVEL if you are not running with administrator privileges?

Choose one answer.

  1. 0
  2. A non-zero value
  3. It cannot be checked because an error is displayed

Wildcards — Question 1

Which file name matches data?.csv?

Choose one answer.

  1. data1.csv
  2. data10.csv
  3. data.txt

Wildcards — Question 2

Who expands wildcards in Command Prompt?

Choose one answer.

  1. Command Prompt expands them and then passes the result to the command
  2. Command Prompt passes them as they are, and the command interprets them
  3. The Windows file system expands them automatically

Other topics

← Back to all practice questions