Programming Field

Scandisk - DOS/Command Prompt Reference

[MS-DOS/Windows 95/98/Me] Checks for errors on the disk (drive).

[Windows NT series] To check for errors, please use Chkdsk.

Syntax

Use any of the following four options.

scandisk[.com] [<drive>: [<drive>: ...] | /ALL] [/MONO]
  [/CHECKONLY | /AUTOFIX [/NOSAVE] | /CUSTOM] [/SURFACE] [/NOSUMMARY]
scandisk[.com] <compress-volume-name> [/MONO]
  [/CHECKONLY | /AUTOFIX [/NOSAVE] | /CUSTOM] [/SURFACE] [/NOSUMMARY]
scandisk[.com] /FRAGMENT <file-name>
scandisk[.com] /UNDO [<undo-drive>:] [/MONO]
<drive>: [<drive>: ...] Specifies the drive(s) to check for disk errors (a colon ‘:’ is required after the drive letter). You can specify multiple drives.
/ALL Checks all disk drives except for removable drives.
/MONO Displays the Scandisk screen in black and white (monochrome). Note that adding ‘DISPLAY=MONO’ to the configuration file ‘Scandisk.ini’ will enable monochrome display even without this option.
/CHECKONLY Performs only the disk error check (do not prompt to repair errors). This cannot be used in conjunction with the /AUTOFIX or /CUSTOM options.
/AUTOFIX

Performs a check for disk errors and automatically repairs them (do not prompt to repair errors). If corrupted data is found, the data will be saved as a file in the root directory of the same drive. This cannot be used in conjunction with the /CHECKONLY or /CUSTOM options.

Note that even if you specify /AUTOFIX, an overview screen of errors will be displayed at the end of the check if errors are found. If you do not want to display this, use the /NOSUMMARY option.

/NOSAVE When automatically repairing, prevents the saving of corrupted data as files. This option must always be specified alongside /AUTOFIX.
/CUSTOM Perform error checking based on the [Custom] section of the Scandisk.ini file. This cannot be used in conjunction with the /CHECKONLY or /AUTOFIX options.
/SURFACE

Automatically performs a cluster scan after the disk check. This takes precedence over the Surface setting in the [Custom] section when the /CUSTOM option is specified.

If /SURFACE is not specified, and none of the options /CHECKONLY, /AUTOFIX, or /CUSTOM are specified, a message will be displayed asking whether to perform a cluster scan after the disk check.

/NOSUMMARY Prevents the display of the check result screen at the end of the check. If this option is specified, the confirmation to create an Undo disk when errors are found will also be skipped.
<compress-volume-name> Performs error checking on unmounted compressed volume files (DoubleSpace/DriveSpace volume files). <compress-volume-name> will be the path to the volume file you want to check.
/FRAGMENT <file-name> Checks whether the file specified by <file-name> is fragmented. No exit code will be set, and only a message indicating whether fragmentation exists will be displayed.
/UNDO [<undo-drive>:]

Based on the Undo disk created by Scandisk, reverts changes made to the drive by Scandisk. <undo-drive>: will be the drive of the disk where Undo data was created with a colon ‘:’.

Note that Undo can only be performed when no changes have been made to the drive since the Undo was created. If changes have been made, the disk may end up in an unexpected state, and the disk might become unusable, so please be cautious.

Details

Scandisk is used to inspect disks in MS-DOS, Windows 95/98/Me. The inspection involves checking the File Allocation Table (FAT), directory structure, file system structure, boot sector, and, if necessary, checking for abnormalities in the disk's clusters (cluster scan).

In a cluster scan, each cluster containing data from a file is read and written to check for errors. For clusters where this operation cannot be performed, the sectors are marked as "bad sectors" and cannot be used thereafter. Disks with high usage frequency or long usage periods may develop clusters that cannot be read or written to due to degradation. To prevent the use of such clusters, it is advisable to periodically perform a cluster scan with Scandisk to mark them.

* The marks of bad sectors can be removed by performing a full format of the disk, but this does not eliminate the errors themselves.
* If there are abnormalities on the disk, Scandisk itself may cause fatal damage to the disk. It is strongly recommended to take a backup in advance if abnormalities are known to exist.

Scandisk cannot check CD drives, network drives, drives created with Subst, and similar drives.

[MS-DOS] During the execution of Scandisk, please refrain from running other programs. If other programs access files while Scandisk is running, it may falsely detect errors, even if the file system is normal.

Scandisk sets an exit code upon program termination. The exit codes are as follows (can be determined using If Errorlevel):

CodeMeaning
0The drive check completed successfully, and no errors were found.
1The command line is incorrect.
2The operation terminated due to insufficient memory or an internal error.
3The check was interrupted by user action.
4The logical check of the drive has completed, but the cluster scan was interrupted by user action during execution. (If the user chooses not to perform the cluster scan, this exit code will not be returned and 0 will be returned.)
254Errors were found on the disk, and all of them have been repaired.
255Errors were found on the disk, but it was not possible to repair all of them.

Samples

Sample 1

scandisk /ALL

Checks all currently available drives (excluding removable drives).

Sample 2 (Batch file)

@echo off
echo Checks for disk errors before starting. When ready, please press any key...
pause > NUL
scandisk /ALL /AUTOFIX /NOSAVE
if errorlevel 255 goto error_exit
if errorlevel 254 goto do_next
if errorlevel 1 goto error_exit

:do_next
setup
goto do_exit

:error_exit
echo Cannot proceed due to errors on the disk.

:do_exit

Checks all currently available drives before running ‘setup’, and if there are errors, prevents the execution of ‘setup’. In this example, if errors are found but repaired, it proceeds with the execution.