Script to add a suffix to selected files

I have had invalubal help developing a simple script which renames files with their respective create date and time.
Now I want to add a popup dialog and prompt me for a suffix to add to ALL filenames.
I have had a go (below) but this script pops up a dialog for every file that is selected.
I want a popup to run once and the same suffix added to all selected files.
Any ideas?
Many many thanks for any suggestions at all...

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("####################################")
	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)

	Dim dlg
	Dim Str_dlg_Show_Return
	Set dlg = DOpus.Dlg
 ' 	Initialise the object to display a message
 ' 	This dialog has a warning icon, a text field allowing the user to enter a line of text,
  	dlg.window = DOpus.Listers(0)
  	dlg.message = "Enter required suffix"
  	dlg.title = "Enter Suffix"
  	dlg.max = 128  ' enable the text field
' 	Show the dialog and print the results to the script log
  	Str_dlg_Show_Return = dlg.Show
  	DOpus.Output "Str_dlg_Show_Return :" & Str_dlg_Show_Return
  	DOpus.Output "dlg.input :" & dlg.input

	
	OnGetNewName=Str_NewName & " " & dlg.input & getNewNameData.newname_ext_m
'
End Function

Are you going to run this from the Rename dialog, or from a toolbar button/hotkey/etc. without opening the Rename dialog?

From toolbar button/hotkey Leo
I did see a post which showed a rename script being run from a button but it looked the same as in the preset area...

Easiest way is to use {dlgstring} in the Rename command (outside of the script) to insert something into the new name, which is then fed into the script.

You could also have a global variable in the script (inside the script, but outside the body of the OnGetNewName function) and have the script check if it is empty. If it is empty, the script could show its own dialog and set the variable to the result. If it isn't empty, the script can use what's in the variable already without showing the dialog a second time.

@Leo (or anyone) would this be from a button script or a rename vb script or can this be done in either?
Thanks...

You might not need a script to add the date time to a file.
This command will ask for for some input, add it to the start of the file name, and add the modified date time to the end.

Rename PATTERN="*.*" TO="{dlgstring|Prepend to file?}* - {modified|D#yyyyMMdd-T#HHmmss}.*" AUTORENAME TYPE=files FILEINFO 
@nodeselect

Or as a button

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>&amp;Append modified</label>
	<tip>Append the modified date and time to the file names</tip>
	<icon1>#rename2</icon1>
	<function type="normal">
		<instruction>Rename PATTERN=&quot;*.*&quot; TO=&quot;{dlgstring|Prepend to file?}* - {modified|D#yyyyMMdd-T#HHmmss}.*&quot; AUTORENAME TYPE=files FILEINFO </instruction>
		<instruction>@nodeselect</instruction>
	</function>
</button>

@wowbagger thank you sir. I am learning more and more about how customisable DO is and I have not seen the rename command used like that before thank you. I have ended up walking down the scripting path for date and time I did not realise it could be done just with a command. I will play around with this....once agian thank you :slight_smile:

1 Like