SortFilesByDate
Purpose
SortFilesByDate searches files matching the passed file pattern in the source folder. It analyses the
files' time stamps and sorts them accordingly in the destination path by creating the necessary folder
structure, with the passed destination path acting as the root folder.
OK, this is a bit abstract. Here are two screen shots showing what's going on. The first one is
from the (sample) source folder. There are a bunch of files in it. Please not the date column (Änderungsdatum).
It shows that there are each 10 files from 2015-01-01 and 2017-03-30 (yyyy-mm-dd):
Lets assume that SortFilesByDate will be run with the following parameters, whereas the above folder's name is
"Source":
SortFilesByDate /sp=.\Source /dp=.\Destination /so=ymd
This tool will now take these files, analyze the time stamps and move them over to the
assigned destination folder, which in the above example is named "Destination".
"Destination" acts as the root folder. Assuming this is the first time we run the
tool, the folder is empty. There are no files nor subfolders present there, before
we run the tool.
After SortFilesByDate has finished however, the contents of the folder "Destination" looks
like:
6 new subfolders were created, reflecting the files' time stamps and each of the files has been moved to the appropriate
folder.
Download
SortFilesByDate
Installation
None. Download the ZIP file, extract the included executable and run it.
Please note: this is a console application. You should run it from a command prompt.
Use case(s)
-
-
There's a bunch of files (invoices, orders, receipts etc.), most likely produced by some kind of automation
and you want to store/sort them in some chronological hierachy for easier retrieval later on.
Or for further processing, where chronological order is important/mandatory.
Syntax
SortFilesByDate /sp=<source folder> /dp=<destination (root) folder>
[/f=<file pattern>[;<file pattern>]] [/so=<sort order pattern>] [/ta=<sort by which time stamp>] [/s=0|1] [/v=0|1]
Parameters:
-
/sp or /sourcepath = start/source folder
-
/dp or /destinationpath = (root) destination folder
-
/f or /filepattern = file pattern. If omitted, all files are scanned (equals /f=*.*).
Multiple file patterns may be specified by using ";" as a separator, i.e. /f=*.doc;Backup*.rtf
-
/so or /sortorder = sorting date/time pattern. Valid values are:
- y - Year
- m - Month
- m - Month
- h - Hour (format 24 HH)
- n - Minute
- n - Minute
-
/ta or /timeattribute = time stamp to analyze for sorting. Valid values are:
- 0 - LastWriteTime (default, if the parameter is omitted)
- 1 - CreationTime
- 2 - LastAccessTime
-
/s or /subfolders = recurse subfolders: yes(1) or no (0). Default is 0, do not recurse subfolders.
-
/v or /verbose = (more) verbose out: yes(1) or no (0). Default is 0.
Examples
SortFilesByDate /sp=.\Source /dp=.\Destination /so=ymd
Analyze all files in Source, move them to the folder Destination and create subfolders corresponding to the files' year, month and day.
If subfolders are present in Source, those won't be touched.
SortFilesByDate /sp=.\Source /dp=.\Destination /f=Invoice_*.pdf /so=y /s=1
Analyze all files matching the file pattern Invoice_*.pdf in Source and all of its subfolders, move them to the folder Destination
and create subfolders corresponding to the files' year.
SortFilesByDate /sp=.\Source /dp=.\Destination /f=??transaction.log;??processing.log /so=ymdhns /s=1
Analyze all files matching the file pattern ??transaction.log and ??processing.log
in Source and all of its subfolders, move them to the folder Destination and create subfolders corresponding to the files'
year, month, day, hour, minute, second.
Source code
The PowerBASIC source code is available at Github
Known issues / limitations
Version
-
1.0.5 - November 2019
-
BUGFIX: parameter /so wasn't validated correctly.
-
1.0.2 - March 2018
-
More detailed help screen.
-
1.0.1 - May 2017
-
Compiler glitch workaround.
-
1.0.0 - April 2017