The following VB script examples show how you can use the command line version of TouchPro for operations that aren't possible from the GUI:
Use (from a command line):
SetFolderTimeToEarliestItemInFolder YourDirectoryName [r]
The optional "r" (recurse) flag makes the script operate in all nested sub-directories.
Use (from a command line):
SetFileTimeTofficeDocTime YourDocumentFileName
Use (from a command line):
SetFileTimeToPictureDateTakenTime YourPictureFileName
Use (from a command line):
SetCreatedToModified YourFileName
e.g. For file with a name format of yyyyMMddhhmmss.ext (such as 20111225010203.ext), this script sets the timestamps to 25'th Dec 2011 01:02:03.
You may need to edit this script to accommodate your specific file naming convention and your date time locale format.
You can further automate these scripts to perform their operation on multiple files or directories using the "For" command like this:
for %F in (*.jpg) do <ScriptName> <parameters - use %F for the filename>
You can do recursive directory processing like this:
for /D /R <path> %F in (*) do <ScriptName> <parameters>
for example:
for /D /R .\ %F in (*) do SetFolderToEarliestFile.vbs %F
... to set each sub-directory timestamp to match that of the earliest file contained in that sub-directory.
More information on the for command.
If you'd like to run a script from a context menu in Windows Explorer so that you just select a file or directory, right click and choose a command, you can add registry entries to create your own commands.
Here's the contents of a .reg file that will add a context menu command to any directory to run the SetFolderTimeToEarliestItemInFolder script. (You will need to modify it for the location where you store the script file).
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\TouchPro - Set Dir To Earliest
Item\command]
@="cscript.exe \"X:\\Path to where your script file is\\SetFolderTimeToEarliestItemInFolder.vbs\"
\"%1\""
If you'd prefer to change the registry manually, here's what you do.
Now, when you right click any directory, you'll see the new command.
This PowerShell script uses TouchProp to extract a date/time property from a file, then applies it to the file's modified timestamp. You can download and unzip the script file, or copy/paste it from here:
# Set a file's modified time from a date/time property via TouchProp
param (
[Parameter(Mandatory=$true)][string]$FileName, #Fully
qualified file path name
[Parameter(Mandatory=$true)][string]$PropertyName
#Canonical property name e.g. System.Message.DateSent
)
#Use
TouchProp to get a property (timestamp) from the file as a PS date/time
value
$dtVal=Get-Date(& 'C:\Program Files\JD Design\TouchPro\TouchProp.exe'
$FileName $PropertyName)
#get the file object
$file = Get-Item $FileName
# change the file's LastWriteTime (Modified) value
$file.LastWriteTime
= $dtVal
Save the above code in a text file and name it SetModifiedFromProperty.ps1
From PowerShell you can now run it like this:
& "C:\MyPathHere\SetModifiedFromProperty.ps1"
It will then prompt you for the FileName and PropertyName parameters.
For the FileName, enter the full path and file name to a file that has an embedded timestamp - such as a JPG
For the PropertyName, enter a canonical property name, for example: System.Photo.DateTaken
You can supply the parameters directly:
& "C:\MyPathHere\SetModifiedFromProperty.ps1" -FileName "C:\MyPictures\photo1.JPG" -PropertyName System.Photo.DateTaken
By adding a few registry settings, you can greatly simplify use of the PowerShell script by just right clicking and choosing a menu option.
The following registry settings (be sure to modify where shown to use the path to where you've saved your .ps1 file):
[HKEY_CLASSES_ROOT\*\shell\TouchPro script
commands]
@=""
"MUIVerb"="&TouchPro Scripts"
"subcommands"=""
[HKEY_CLASSES_ROOT\*\shell\TouchPro script commands\shell]
@=""
[HKEY_CLASSES_ROOT\*\shell\TouchPro script commands\shell\Set
Modified from System.DateCreated]
[HKEY_CLASSES_ROOT\*\shell\TouchPro script commands\shell\Set Modified
from System.DateCreated\command]
@="powershell \"C:\\MyPathHere\\SetModifiedFromProperty.ps1\" -FileName
'%1' -PropertyName System.DateCreated"
[HKEY_CLASSES_ROOT\*\shell\TouchPro script commands\shell\Set Modified
from System.Message.DateSent]
[HKEY_CLASSES_ROOT\*\shell\TouchPro
script commands\shell\Set Modified from System.Message.DateSent\command]
@="powershell \"C:\\MyPathHere\\SetModifiedFromProperty.ps1\"
-FileName '%1' -PropertyName System.Message.DateSent"
[HKEY_CLASSES_ROOT\*\shell\TouchPro script commands\shell\Set Modified
from System.Photo.DateTaken]
[HKEY_CLASSES_ROOT\*\shell\TouchPro
script commands\shell\Set Modified from System.Photo.DateTaken\command]
@="powershell \"C:\\MyPathHere\\SetModifiedFromProperty.ps1\"
-FileName '%1' -PropertyName System.Photo.DateTaken"
Adds the following right click menu items for any file:
The first command copies the file's Created date property to the Modified property.
The second copies the System.Message.DateSent property (usually present in an email .eml file) to the file's Modified property.
The last copies the System.Photo.DateTaken property (usually present in camera image files) to the file's Modified property.
You can download the REG file here. Don't forget to edit it to refer to the location where you've saved the PS1 file before you merge it into your registry.