This program deletes files, which have a given age, but keeps a certain number of the youngest files.
The search is restricted to one directory; recursive processing is not supported until heavily requested.
One or more pattern for the file names must be given.
Write protected files are never deleted. Instead they cause an error message and an specific errorlevel (see below). The program will continue with the next file.
Options are given in the form:
<option switch><option name>[=[option value]]
(Values in angle brackets ('<>') must be given, values in square brackets ('') may be omitted.)
White spaces are not allowed between these components.
Examples: '--Option1=Value1', '-a=90'
The option switch is either one hyphen '-' for short option names, which consist of only one character, or double hyphen ('--') for long option names, which consist of more than one character.
If the option is a boolean value, the option value and the equal sign can be omitted to use the default value (almost TRUE, see program help for details). Example: instead of '--BoolOpt=true' the option '--BoolOpt' can be used, if the default value is TRUE.
If the option is a string value, it meight be possible to assign an empty string. This can be done by omitting the option value, but not the equal sign. Example: '--StringOpt=' would set the option value to an empty string. Don't use '--StringOpt=""': this would set the string to two quotation marks!
If an option value contains white chars, you must protect them on the command line (and only there, not in configuration files), because otherwise Windows would break this option into multiple parts. Set double quotation marks around the whole option to do it. <Example>"--StringOpt=A Value With Spaces"</Example>.
Order of Options
Options at the command line are read from left to right, in configuration files from top to bottom (so set the LOGFILE option first to see possible parsing errors, if executed without a visible window).
Options may occure multiple, and depending on that specific option either the previous given value is overridden or the value is added to a list.
When a configuration file is given at the command line or in a another configuration file, it is parsed at the position of occurance.
When the program is started, it looks for a configuration file named PROGAMNAME.conf in the same directory (PROGAMNAME is the the name of the EXE file). If found, it is parsed before the command line options. You can set your default options in this file.
Relative Directory Names in Options
Relative directory names (e.g. starting with '..') are resolved to the point of definition:
If given on command line, the program directory is used.
If given in a configuration file, the directory name is expanded with the configuration file directory.
Minimum age in days. If not given, 0 is assumed.
-D|--directory=[an existing directory]
Directory to work in. If option is not given, the current directory is used.
Do not really delete, just show what would be deleted.
Shows the help and quits.
-c|--conffile=<an existing file>
Filename for configuration file. If not given, PROGRAMNAME.CONF in program directory is used.
Keep at least this number of objects. If not given, 0 is assumed.
-l|--logfile=[any file name]
Append output to file LOGFILE.
-p|--pattern=<a non empty string>
Pattern for the file names to treat. At least once required.
Format for time stamp. Default is "c ". See docs for more info.
Set the verbose level. If not given, 1 is assumed (0=no output except errors).
Print the version of this program end quit.
-x|--exclude=<a non empty string>
Exclude this file. May occure multiple.
Every working message output has a time stamp at the beginning, created by the Delphi *FormatDateTime* function. The default format is "c ", which uses windows system format settings for date and time.
You can change the format of the time stamp with the option *TimeStampFormat*:
y = Year last 2 digits
yy = Year last 2 digits
yyyy = Year as 4 digits
m = Month number no-leading 0
mm = Month number as 2 digits
mmm = Month using ShortDayNames (Jan)
mmmm = Month using LongDayNames (January)
d = Day number no-leading 0
dd = Day number as 2 digits
ddd = Day using ShortDayNames (Sun)
dddd = Day using LongDayNames (Sunday)
ddddd = Day in ShortDateFormat
dddddd = Day in LongDateFormat
c = Use ShortDateFormat + LongTimeFormat
h = Hour number no-leading 0
hh = Hour number as 2 digits
n = Minute number no-leading 0
nn = Minute number as 2 digits
s = Second number no-leading 0
ss = Second number as 2 digits
t = Use ShortTimeFormat
tt = Use LongTimeFormat
am/pm = Use after h : gives 12 hours + am/pm
a/p = Use after h : gives 12 hours + a/p
ampm = As a/p but TimeAMString,TimePMString
/ = Substituted by DateSeparator value
: = Substituted by TimeSeparator value
'xx'/"xx" = Strings surrounded by single or double quotes are shown as they are
Possible verbose levels are:
0: silent - only errors are shown
The program ends with an errorlevel. Possible errorlevels are:
0: no error
1: option parsing error
2: a directory does not exist
3: could not write to logfile
4: could not retrieve file attributes
5: could not delete file
This is free software: you are free to use and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
This software was written by
[+] feature added
[-] feature removed
version 0.2.1, 2014-09-12
[b] worked around the MAX_PATH length by adding "\\?\" prefix if file name len exceeds MAX_PATH
[c] on parsing errors the used option name is reported, not just the first name of an option
version 0.2, 2014-04-20
[c] parsing error messages are now written to the log file, if any given
[+] release date is print out on version infos
[c] on parsing errors the option name given by parser is included in error message
version 0.1.1, 2014-01-09
[b] bugfix in handling TimeStamp-Option
[+] improved documentation
version 0.1, 2013-11-28
[b] bugfix in handling empty strings in options
[+] added option for excluding files
version 0.0.2, 2013-10-12
[b] solved problem with unicode characters in file names
[+] version infos are now added to the EXE-file
version 0.0.1, 2013-09-15
[c] deleted or skipped files are displayed with directory now
[b] bugfix at integer options
[+] improved version infos and documentation
version 0, 2013-09-15
[+] first release