I collect here small programs I wrote in order to get familiar with
specific technical problems. These code snippets are normally very short - they
concentrate on the essence of the problems. They may contain code that I
found elsewhere on the internet. Note that my snippets do not answer all questions
related with the given problem: if you look into the code you will see that
very often open questions still exist!
Directory traversal(Linux and Windows)
I often need functions to traverse directories under Linux and Windows. Strange enough -
there is no common API that works for both operation systems (if you use WxWidgets or
PHP or similar frameworks then you have a common API). Here is the basic C++ code for
Windows 32 Bit. A
similar basic source code for Linux is here.
I didn't consider seriously the
method system("dir ...") under Windows or system("ls ...") (Linux).
Simple backup to a remote server (Windows)
I find the usual backup programs difficult to configure. I wrote therefor this simple
based on the directory traversal program described above. It is designed to help people like me - i.e.
typically software engineers changing every day source code, configuration files or documentation.
A Windows executable (32 Bit) is here.
This simple program (only ca. 400 lines of C++ code)
is based on the the following ideas:
It is essential that FTP supports the option "-s:controlFile" (not all FTP versions support this option).
A typical control file (named "ftpcmd.pat") looks like this:
- Runs in a command line window (shell window, "black" window)
- Assumes that the backup is directed to a remote server
- Uses the command line FTP command to transfer the files to the remote server (the FTP
version in the Windows standard)
- Transfers only files that are equal to or newer than the date given in the command line argument
- Uses a control file "ftpcmd.pat" that is manipulated by the program. The resulting
file "ftpcmd.txt" is used by the FTP command
- can be invoked in test mode (option "-test"). Outputs then the number of
files that will be saved and the total number of bytes
You may change or enhance this control file pattern in order to reflect your needs. Please test it then
in a "black window" before it is used by backupEH.
Note that the line "put " (the space after "put" is important) is modified by this program:
the program appends there the respective backup candidate file.
The FTP command is executed for each single file that meets the date requirements.
A typical parameterized call of the program:
backupEH .\mySources 2016-08-26
The first parameter is the directory from which the backup starts. The second
parameter is the date from which on files are considered.
Note that the given date must always be in format "YYYY-MM-DD".
I think the source code is well documented. Compile it with the Digital Mars C++ compiler( modify the
include path in option -I):
DMC -mn -DDMC -DWIN32 -Ic:\huckert\dm\stlport backupEH.cpp
The program filters out some file types like .map files or .obj files.
You may change that in the source code.
This program uses no special libraries except STL (and even STL is not absolutely needed).
It should also be compilable with Microsoft C++ oder GNU g++.
Note that I didn't write this for UNIX/Linux though it should run there with a few changes. I didn't test
it neither under other versions of Windows except Windows 7. As mentioned above this solution depends
heavenly on the command line program FTP - several incompatible versions may exist in the Windows world.
JAVA samples. Shows simple sample code for
the most frequent application classes: IO, exceptions, string handling, GUI (Swing),
collections, inheritance (derivation) and XML. I use this sample code if
I have to write JAVA programs again after longer projects in C++ or PLSQL or other
programming languages when I simply forgot the basic JAVA techniques.
If you want to contact me: this is my