i create this script to cut n character at the begin/end of file.
but i have problem with inputboxes. can you help me please.
[code]@script vbscript
Option Explicit
Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )
Dim Debut, Fin, Ext
Debut = inputbox ("Nombre de caractères à rogner au début du fichier.","Rogner n caractères à gauche")
Fin = inputbox ("Nombre de caractères à rogner à la fin du fichier.","Rogner n caractères à droite")
That's because Opus calls the Rename_GetNewName function for each selected file.
After a brief look at this there are only a couple of alternatives I can see.
Force the values from within the code and don't prompt for them.
Ask for the values, then store the results in a temporary file. If the temporary file exists don't ask for the values again. This would require the temp file to be deleted at the end of the rename somehow otherwise subsequent renames would reuse the same values and not prompt again.
If you're making something that you will run from a button, rather than a rename preset that you'll select from the Rename dialog, then you could probably ask for the number in the button (using {dlgstring}) and then pass that number as part of the old or new filename to the rename command.
Your VBScript could then assume that the old (or new) name had a number stuck on the front of it and split the name into that number and the real name.
A bit messy but it might work.
If you only need the option of removing a small range of characters (say, between 1 and 5 characters) then having separate buttons or rename presets might be easier. If you need the option of a bigger range then a script that takes an argument like yours obviously makes more sense.
You can do this by declaring the variables outside the rename function. They will then be global to the script and retain their value for each file.
For example,
@script vbscript
Option Explicit
Dim Debut, Fin
Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )
if Len(Debut) = 0 Then
Debut = inputbox ("Nombre de caractères à rogner au début du fichier.","Rogner n caractères à gauche")
end if
if Len(Fin) = 0 Then
Fin = inputbox ("Nombre de caractères à rogner à la fin du fichier.","Rogner n caractères à droite")
end if
Dim Ext
Ext = Right(strFileName, Len(strFileName)-(InStrRev(strFileName, ".")-1))
strNewName = Right(strFileName, Len(strFileName) - Debut)
strNewName = Left(strNewName, Len(strNewName) - Fin - Len(Ext)) & Ext
End Function