Command-line examples

Following are several WinContig command-line examples.

Basic operations

Run the following command to defragment all files located in the c:\data folder and related subfolders.

wincontig "c:\data" /defrag

Run the following command to defragment all files located in the c:\data folder and related subfolders without checking for disk errors and without deleting temporary files.

wincontig "c:\data" /defrag /chkdsk:0 /clean:0

Run the following command to defragment all files located in the c:\data folder excluding subfolders.

wincontig "c:\data" /defrag /nosubdirs

Run the following command to analyze all files located in the c:\data folder and related subfolders to determinate how fragmented the files are.

wincontig "c:\data" /analyze

Run the following command to defragment only executable files located in the c:\data folder.

wincontig "c:\data\*.exe" /defrag

Run the following command to defragment only executable files located in the c:\data folder and related subfolders.

wincontig "c:\data\*.exe" /recurse /defrag

Run the following command to analyze only executable files and document files located in the c:\data folder and related subfolders.

wincontig "c:\data\*.exe" "c:\data\*.txt" /recurse /analyze

Run the following command to defragment all files located in the c:\data folder and related subfolders, and automatically close WinContig once the defragmentation process has been completed.

wincontig "c:\data" /defrag /close

Run the following command to defragment all items listed in the c:\data\myprofile.wcp profile.

wincontig /prof:"c:\data\myprofile.wcp" /defrag

Run the following command to defragment all files located in the c:\data folder and related subfolders without showing the user interface of WinContig.

wincontig "c:\data" /defrag /nogui

Advanced operations

Run the following command to move only executable files located in the c:\data folder to the fast access zone of the volume. If a file cannot be moved to the fast zone of the volume, that file will be skipped.

wincontig "c:\data\*.exe" /defrag /diskzone:fast

Run the following command to move only executable files located in the c:\data folder to the fast access zone of the volume. If a file cannot be moved to the fast zone of the volume, WinContig will try to move that file to the first available contiguous run of free clusters that is large enough to contain the entire file. Notice the use of the asterisk (*) in the /diskzone switch.

wincontig "c:\data\*.exe" /defrag /diskzone:fast*

Run the following command to move all files located in the c:\data folder and related subfolders to the first available contiguous run of free clusters that is large enough to contain an entire file starting from the disk cluster 1234. Notice the use of the asterisk (*) in the /diskzone switch.

wincontig "c:\data" /defrag /diskzone:1234*

Batch script example

When using the /nogui switch, WinContig provides exit codes that indicate the level of success for a command. You can create a batch script to perform an operation and use the script if command to process the exit code if an error occurs.

Check the following batch script example to learn how to process exit codes.

@echo off

:: Defragment all files located in the 'c:\data' folder and related subfolders.
:: The disk is automatically checked for errors.

wincontig "c:\data" /defrag /chkdsk:1 /nogui

if errorlevel 5 goto notfound
if errorlevel 3 goto incomplete
if errorlevel 2 goto diskerror
if errorlevel 0 goto success

:: the specified folder does not exist.
:notfound
echo.
echo WinContig cannot find the specified folder.
echo The defragmentation operation has been canceled.
exit /b 0

:: one or more files have not been defragmented.
:incomplete
echo.
echo WinContig was unable to successfully defragment all files.
echo Some files are still fragmented.
exit /b 0

:: errors were found during the checking of the disk.
:diskerror
echo.
echo WinContig has detected problems with the disk.
echo The defragmentation operation has been canceled.
exit /b 0

:: all files have been defragmented.
:success
echo.
echo Defragmentation successfully completed.

See also