FileWatcher - .vbs generate random names and print slip

Discuss our other products here. Get help with installation and running, notify us of bugs, request new features and enhancements.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia

FileWatcher - .vbs generate random names and print slip

Post by DataMystic Support »

The code below can be used to get File and Folder Watcher to watch file new photos arriving, then generate a unique (random) name for each file, move it to a processed folder and then generate a small text file to be printed out to give to the customer. Perfect for mobile photographers and PhotoMarketing!

Code: Select all

'FileWatcher script - move files to processed folder, and generate printer stub for them

Option Explicit

const processed = "c:\processed\"
const codes = "c:\codes\"
const prefix = "ABCD"

dim objArgs
dim fso
dim filename

Function ExecuteWithTerminalOutput(cmd)
	dim WshShell
            Set WshShell = WScript.CreateObject("WScript.Shell")
            'use this line to hide the window, and wait until the new process finishes
            'useful for debugging
            WshShell.Run cmd, 1, true
            'use this line below when debugging is not needed
'            WshShell.Run cmd,0

            ExecuteWithTerminalOutput = 0
End Function

Function random_name( filename )

	dim MyFile
	dim new_id
	dim new_name
	dim print_file

		new_id = Int( 1000000 * Rnd + 1 )
		new_name = processed & prefix & new_id & ".jpg"
	Loop While fso.FileExists( new_name )

	random_name = new_name	

	'generate file to print
	print_file = codes & new_id & ".txt"
	Set MyFile = fso.CreateTextFile( print_file, True)
	MyFile.WriteLine( "My photography company,")
	MyFile.WriteLine( "Your photo id: " & new_id)
	MyFile.WriteLine( "------------------------" )

	'now print it
	ExecuteWithTerminalOutput("NotePad.exe /p " & print_file )

end Function 

'---------------- start ----------------

Set fso = CreateObject("Scripting.FileSystemObject")

'Set a reference to the arguments
Set objArgs = Wscript.Arguments

dim move_name

for each filename in objArgs

	If fso.FileExists( filename ) Then
		move_name = random_name( filename )
		fso.MoveFile filename, move_name
	End If


Set fso = Nothing
Set objArgs = Nothing

Photo marketing is a generic term for when photography is used to deliver a call to action for a brand. It is the process where you take a photograph or video with the aim of getting people, i.e. your target audience to interact with your brand offline and online. It is very useful for your brand to have a tool that can drive people to online or social channels where the brand experience they enjoyed and remember is further extended into the online environment.
Post Reply