{createddate} and {createdtime} from within a script

I wish to access the following from a VBScript within the renaming dialog scripting facility:
{createddate} and {createdtime}
Any idea how I could achieve that?
Many thanks for any reply...

I intend starting with scripts in this very useful post:

The script is passed an "item" object for the file which includes details such as its modified date.

@Leo thank you.
Am I right in saying....

  • The Script to perform multiple regular Expressions (link above) is written with the call to the legacy rename script function Rename_GetNewName.
  • The item object is only acessible when using the new/current rename script function OnGetNewName.
  • Therefore to access the item object I need to rewrite the afore mentioned script using the new rename script function OnGetNewName.

Many thanks as always for any reply

Correct, although it is nothing complicated, just some different variable names.

After some rading I am tackling this script.
The idea is to rename files with the Created date and time

What is the matter with this attmept below?
Grateful as always for any reply

Option Explicit
Function OnGetNewName(ByRef getNewNameData)
'
	OnGetNewName=GetNewNameData.item.metadata.DocMeta.created
'
End Function

When I load it I get this error:

Error at line 4, position 2
Object doesn't support this property or method: 'getNewNameData.item.metadata.DocMeta' (0x800a01b6)

Item.MetaData.DocMeta will only exist for things like Office documents.

You don't need to use the Item.MetaData object at all if you just want the basic file dates and times. The Item object gives you those by itself.

@Leo thanks. I tried ths below and got very unexpected results.
Was this what you meant? Below
Sorry for screenshot was not sure how else I could show this:

You need to format the date/time to the way you want it to look in the filenames.

Default date/time formatting uses : between the time parts. e.g. 14:22:15 is the current time for me. That won't work in a filename as : characters aren't allowed.

Use DOpus.Output to print what variables contain to the output window below the script editor. That should make it clear what your script is doing and what needs to be changed.

My electricity is being re-wired today and I barely have semi-working internet access at the moment so your best bet is to find some example scripts or read through the manual for the different scripting objects.

1 Like

That makes sense I will do this thank you Leo as ever

After much ado i have got this far.
This script works but drops the extension:

Option Explicit
Function OnGetNewName(ByRef getNewNameData)
'
	Dim Str_NewName
'	OnGetNewName=getNewNameData.item.create
'	DOpus.output getNewNameData.item.create
	Str_NewName = getNewNameData.item.create
	DOpus.Output("Str_newName: " & Str_newName)
	Str_NewName = Replace(Str_NewName,":","h",1,1)
	Str_NewName = Replace(Str_NewName,":","m",1,1)
	DOpus.Output("Str_newName2: " & Str_newName)
	OnGetNewName=Str_NewName
'
End Function

Reading up I had reason to think this would include the extension but I get a coding error (below):
Why would this be?

Option Explicit
Function OnGetNewName(ByRef getNewNameData)
'
	Dim Str_NewName
'	OnGetNewName=getNewNameData.item.create
'	DOpus.output getNewNameData.item.create
	Str_NewName = getNewNameData.item.create
	DOpus.Output("Str_newName: " & Str_newName)
	Str_NewName = Replace(Str_NewName,":","h",1,1)
	Str_NewName = Replace(Str_NewName,":","m",1,1)
	DOpus.Output("Str_newName2: " & Str_newName)
	getNewNameData.newname_stem=Str_NewName
'
End Function

This is the error I get:

Error at line 13, position 2
A method was called unexpectedly (0x8000ffff)

All the getNewNameData properties are read-only. The script changes the name by returning a string, not by modifying anything within getNewNameData.

The old extension is given to you in getNewNameData.newname_ext or getNewNameData.newname_ext_m (the second one is usually best, depending on what you're doing). Append that to the string you are returning if you want to keep it as the filename's extension.

This is my code as it stands.
Below. Still extension is missing.
getNewNameData.newname_ext and getNewNameData.newname_ext_m seem to be giving empty outputs..?

Option Explicit
Function OnGetNewName(ByRef getNewNameData)
'
	Dim Str_NewName
'	OnGetNewName=getNewNameData.item.create
'	DOpus.output getNewNameData.item.create
	Str_NewName = getNewNameData.item.create
	DOpus.Output("Str_newName BEFORE: " & Str_newName)
	Str_NewName = Replace(Str_NewName,":","h",1,1)
	Str_NewName = Replace(Str_NewName,":","m",1,1)
	DOpus.Output("Str_newName AFTER: " & Str_newName)
	DOpus.Output("getNewNameData.newname_stem: " & getNewNameData.newname_stem)
	DOpus.Output("getNewNameData.newname_ext: " & getNewNameData.newname_ext)
	DOpus.Output("getNewNameData.newname_ext_m: " & getNewNameData.newname_ext_m)
	OnGetNewName=Str_NewName & getNewNameData.newname_ext_m
'	getNewNameData.newname_stem=Str_NewName
'
End Function

DOpus.output is giving (BTW How do you clear the DOpus.output?):

Str_newName BEFORE: 2017-05-29 12:38:36
Str_newName AFTER: 2017-05-29 12h38m36
getNewNameData.newname_stem:
getNewNameData.newname_ext:
getNewNameData.newname_ext_m:

It's possible the settings in the Rename dialog are generating an empty name which is then passed into your script.

What does the Rename dialog look like?

Please also show some example things which are being renamed as the inputs affect the outputs. For example, if you are renaming folders then they won't have extensions, even if there are dots in the folder names.

This morning it is working. Cannot repoduce the fault.
Thank you Leo for your help. Thank you...