DEFRAG source code: Program your own defragmenter-computer image

With a defragmentation program (defragmenter, defrag tool), arrange the components of each covered file so that you are physically in succession. This ensures a faster reading on the writing head of the ferromagnetic hard drive involved. So far we have explained explanations and tips in various articles Fragmentation and Defragmentation given.

In the present article, we take up a border issue of the whole: How to develop your own DEFRAG program. Why should you program something like that? The advantages are that the resulting piece of software can be slim and, in that case, only a few resources. Furthermore, for some the factors are “feasibility” exploring “,” really useful “and” educational “factors that play in here. We limit ourselves to some basics below.

A defragmenter with little programming – what you need for it

A defragmenter can be programmed in a rather stupid way by one Batch file Create: You put one with the Windows’s own editor on, which you with Windows-R and the command Notepad Call up. In Notepad, copy one or more command line commands for drive optimization, such as this:

Defrag C: /O

Defrag D: /O

Defrag f: /o

With Ctrl-S you save, putting a script file with the ending “.cmd” in a folder of your choice. Right click on the file and with “Run as administrator” call the work. The /o parameter takes place for each drive that is specified via its drive letter, the ideal maintenance: a hard drive is defragmented and an SSD is trimmed.

Contig miss a gui-anlitz

Contig

Contig drilled: knew how, the use of the tool succeeds more comfortably than normally.

Photo: computer picture

Microsoft offers with Contig a downloadable defragmenter (no third-party tool because the provider is identical to that of Windows). He is able to defragment individual files, which is not and not with the internal “dfrgui.exe” tool. With “defrag.exe” only with dislocations goes.
Contig runs in the Command line And therefore requires appropriate commands for its use. With a registry hack, install Contig into the context menu of your files so that you can tune them with the contig-engine inside after a click on you. If you wish, you can “programmate” to have such a registry hack in a Batch file, also a reg file for quick automation of a corresponding modification (on another PC).

A possible procedure:

1. Download Contig and unzip the “Contig64.exe” file from the obtained zip archive.

2. Open with Windows-R and the command regalite the Registry editor. Get the following registry key path forward:

HKEY_Classes_root \*\ Shell

3. Create a registry key with “Edit> New> Key”, which you call “Defrag”. This means the new command/entry in the context menu of your files for defragmentation.

4. Create a sub key from “Defrag” with the same click sequence. Name him “command”.

Ashampoo WinopTimizer as a free full version for download

Download the win optimizer for free as a full version

You can download the Ashampoo WinopTimizer 26 here as a free full version and use it for free.

5. With marked “Command” Subkey in the right window area, click twice on the registry entry “(Standard)”. Date the following command:

“%1”

6. Optionally, give your context menu input/command a symbol by create a registry entry called “Icon” in the “Defrag” key via “Edit> New> String”. In it they give a symbol file path like C: \ Windows \ System32 \ dfrgui.exe to.

A disadvantage of the new “Defrag” context command: It does not work in Windows Explorer. Because Contig needs administrator rights and there is no UAC query to acquire these privileges in the tuning procedure. Approaches to remedy: You are experimenting with the Task planning (Taskschd.msc, schtasks.exe) expanded rights and that Uac-free to obtain. Or – easier – you invite the external file manager “Q-thir“Down and start with administrator rights: In the tool right-clicked files receive a defrag maintenance if you go to the” Defrag “context command.

Integrate the contig in Total Commander

Totally commander

The Total Commander allows individualization by integrating (Defrag) software.

Photo: computer picture

Again Contigsee the above article sales: You build this command line defragmenter in the GUI (Graphical Userum Interface, graphic user interface) of the file manager “Totally commander“A. The software takes a seat in the form of a new icon in the toolbar above and allows the file to be defragmented in the application.

The procedure for setting up the whole includes a few steps:

1. Download the totally commander and call it up.

2. Duplicate the Notepad icon in the above toolbar on the right by clicking it right and going to “Copy”; Whereupon you make right -click and command “inserting”.

3. Click the new icon with the right mouse button and select “Change” in the context menu.

4. In the windows that open up, put in the “Command” field at the top of the “Command” cmd.exe /k to. Below with “Parameter” you store the following:

-v %p %n & exit

5. Optionally, they also assign a suitable symbol to the right of “Icondatei” on the right and navigate to C: \ Windows \ System32 \ dfrgui.exe.

To defragment a file, select it in Total Commander with a click. Then right -click the new symbol and choose “as administrator”. If you have started the Total Commander with administrator rights, equivalent is sufficient to get left-click on the fresh illustration.

Ashampoo WinopTimizer as a free full version for download

Download the win optimizer for free as a full version

You can download the Ashampoo WinopTimizer 26 here as a free full version and use it for free.

Program Defragmenters – with “own” engine

Last but not least, you can create a batch file to which you pull your files on the drag & drop to defragment them. The DEFRAG procedure looks like a corresponding file is copied. Such a copy – depending on the physical circumstances on the data carrier – is steady or fragmented as possible. The original file is deleted and the copy is renamed so that it bears the original file name again.

The following batch code, for example, makes it possible:

@echo off
Setlocal Enabledelayed expansion

:: check whether a file was handed over by drag & drop
if “%~ 1” == “” (
Echo pull a file onto this script to defragment it.
pause
Exit /b
)))

:: File path and name extract
Set “Filepath =%~ 1”
Set “Filename =%~ nx1”
Set “Dirpath =%~ dp1”
Set “Tempfile =%Dirpath %% Random%_%Filename%

:: Copy the file and delete original
Copy “%Filepath%” “%Tempfile%”> Nul
del “%Filepath%”

:: rename copy back
ren “%tempfile%” “%filename%”

Source link