TouchPro Scripting Examples

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:

Sets a directory's timestamp to that of the earliest file or sub-directory in the directory:

Use (from a command line):

SetFolderTimeToEarliestItemInFolder YourDirectoryName [r]

The optional "r" (recurse) flag makes the script operate in all nested sub-directories.

Sets an Office document file timestamp to the same as its embedded timestamp:

Use (from a command line):

SetFileTimeTofficeDocTime YourDocumentFileName

Sets a picture file's modified time to be the same as the picture's "Date Taken" timestamp:

Use (from a command line):

SetFileTimeToPictureDateTakenTime YourPictureFileName

Sets a file's created time to be the same as its modified time:

Use (from a command line):

SetCreatedToModified YourFileName

Set's a file's created and modified time from a timestamp derived from its file name:

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.

Repeating Scripts using the "for" Command

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.

Running Scripts from a custom Context Menu in Windows Explorer

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.

  1. Run regedit.
  2. Navigate to: HKEY_CLASSES_ROOT\Directory\shell (if you want to add the command for all directories)
  3. Create a new registry key, giving it the name you want to see in the context menu.
  4. Select the newly created key and create a new registry key under there, naming it "command" (without the quotes)
  5. Set the value of the Default value of this command to execute the script. For this example it's:
    cscript.exe "C:\Your Path Here\SetFolderTimeToEarliestItemInFolder.vbs" "%1"

Now, when you right click any directory, you'll see the new command.

Using PowerShell to set a file's modified time from a date/time property of the file

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

Invoke the PowerShell Script from Explorer

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"

[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:

Touch Menu Items

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.