Automatic Defragmentation

Defragmentation can be easily fully automated. Just click Settings > Preferences, open the Automatic defragmentation tab, select the disks you would like to defragment automatically and click OK.

By default the program performs automatic defragmentation once a day when the computer is idle. To adjust defragmentation schedule click Settings > Preferences, open the Automatic defragmentation tab and click Schedule. Alternatively, you can adjust the schedule directly in Windows Task Scheduler.

Note
  • By default the automatic defragmentation will not be performed when the computer runs on batteries.
  • To prevent waste of time the program disables the following built-in task on Windows Vista and more recent Windows editions:
    Task Scheduler Library\Microsoft\Windows\Defrag\ScheduledDefrag.

Also it is possible to execute a custom script during the automatic defragmentation. Just click Settings > Preferences, open the Automatic defragmentation tab, select the Execute custom script option there and click OK. To adjust the script click Edit custom script or open the following file manually in a text editor: {installation folder}\tasks\auto-defrag-custom.cmd.

By default the program uses the following custom script:

@echo off
::
:: UltraDefrag - a powerful disk defragmenter for Windows.
::
:: auto-defrag-custom.cmd - custom script for automatic defragmentation.
::
:: Visit https://en.wikibooks.org/wiki/Windows_Batch_Scripting
:: for general information about the script syntax.
::
:: Refer to the Console chapter of the UltraDefrag Handbook for detailed
:: information about the `udefrag` command and environment variables
:: controlling its behaviour. You should have received the handbook
:: along with this program, if not, you can find it at the official
:: UltraDefrag website (https://ultradefrag.net/)
::
:: To use Unicode characters in filters edit this file in the Notepad++
:: editor and then save it in UTF-8 (without BOM) encoding.
::
:: Also Notepad++ features syntax highlighting which makes it much easier
:: to edit the file. The latest version of Notepad++ can be downloaded
:: for free from http://www.notepad-plus-plus.org/
::
:: Below is a sample script. It defragments system drive and heavily
:: fragmented content on all the connected non-removable drives.
:: Feel free to adjust it to make it more suitable for your needs,
:: replace it entirely or keep as is.
:: first of all, let's set UD_EX_FILTER to exclude all
:: the stuff which rarely benefits from defragmentation
:: exclude temporary content
set UD_EX_FILTER=*system volume information*;*temp*;*tmp*;*recycle*
set UD_EX_FILTER=%UD_EX_FILTER%;*dllcache*;*ServicePackFiles*;*.log
set UD_EX_FILTER=%UD_EX_FILTER%;*Windows.old*
:: exclude archives
set ARCHIVE_PATTERNS=*.7z;*.7z.*;*.arj;*.bkf;*.bz2;*.bzip2;*.cab;*.cpio;*.deb
set ARCHIVE_PATTERNS=%ARCHIVE_PATTERNS%;*.dmg;*.gz;*.gzip;*.lha;*.lzh;*.lzma
set ARCHIVE_PATTERNS=%ARCHIVE_PATTERNS%;*.rar;*.rpm;*.swm;*.tar;*.taz;*.tbz
set ARCHIVE_PATTERNS=%ARCHIVE_PATTERNS%;*.tbz2;*.tgz;*.tpz;*.txz;*.xar;*.xz
set ARCHIVE_PATTERNS=%ARCHIVE_PATTERNS%;*.z;*.zip
set UD_EX_FILTER=%UD_EX_FILTER%;%ARCHIVE_PATTERNS%
:: exclude multimedia content
set AUDIO_PATTERNS=*.aif;*.cda;*.flac;*.iff;*.kpl;*.m3u;*.m4a;*.mid
set AUDIO_PATTERNS=%AUDIO_PATTERNS%;*.mp3;*.mpa;*.ra;*.wav;*.wma
set VIDEO_PATTERNS=*.3g2;*.3gp;*.asf;*.asx;*.avi;*.flv;*.mov;*.mp4
set VIDEO_PATTERNS=%VIDEO_PATTERNS%;*.mpg;*.rm;*.srt;*.swf;*.vob;*.wmv
set UD_EX_FILTER=%UD_EX_FILTER%;%AUDIO_PATTERNS%;%VIDEO_PATTERNS%
:: exclude virtual machines
set DISK_IMAGE_PATTERNS=*.fat;*.hdd;*.hfs;*.img;*.iso;*.ntfs;*.squashfs
set DISK_IMAGE_PATTERNS=%DISK_IMAGE_PATTERNS%;*.vdi;*.vhd;*.vmdk;*.wim
set UD_EX_FILTER=%UD_EX_FILTER%;%DISK_IMAGE_PATTERNS%
:: exclude big fragments which rarely benefit from defragmentation
set UD_FRAGMENT_SIZE_THRESHOLD=20MB
:: if your system drive is an SSD uncomment the following
:: line to exclude slightly fragmented content as well
:: set UD_FRAGMENTS_THRESHOLD=20
:: uncomment the following line to increase amount of debugging output
:: set UD_DBGPRINT_LEVEL=DETAILED
:: defragment system drive
set UD_LOG_FILE_PATH=%UD_INSTALL_DIR%\logs\autodefrag-system.log
udefrag --wait %SystemDrive%
:: defragment heavily fragmented content
:: on all the connected non-removable drives
set UD_LOG_FILE_PATH=%UD_INSTALL_DIR%\logs\autodefrag-fixed.log
set UD_FRAGMENTS_THRESHOLD=20
udefrag --wait --all-fixed