TouchPro: TouchCmd 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:

1. This example sets a directory's timestamp to that of the earliest file or sub-directory timestamp contained in the directory: SetFolderTimeToEarliestItemInFolder.zip

Use (from a command line):

SetFolderTimeToEarliestItemInFolder YourDirectoryName [r]

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


2. This example sets an Office document file timestamp to the same as its embedded timestamp: SetFileTimeToOfficeDocTime.zip

Use (from a command line):

SetFileTimeTofficeDocTime YourDocumentFileName


3. This example sets a picture file's modified time to be the same as the picture's "Date Taken" timestamp: SetFileTimeToPictureDateTakenTime.zip

Use (from a command line):

SetFileTimeToPictureDateTakenTime YourPictureFileName


4. This example sets a file's created time to be the same as it's modified time: SetCreatedToModified.zip

Use (from a command line):

SetCreatedToModified YourFileName


5. This example set's a file's created and modified time from a timestamp derived from its file name: SetFileTimeFromDateInFileName.zip

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.