Hi
How can I add the Sequential numbering option in a rename script? How can add the other non-scripted options in the rename dialog (capitalization, automatic numbering, etc)?.
I want's to write a rename script for rename selected files with there parent folder name with sequential number. Yes I know this job need not any script at all. standard command can do this. but I want's to understand how the script works?
function OnGetNewName(getNewNameData)
{
var item = getNewNameData.item;
var orginalext = item.ext;
var parentfolderName = item.path.filepart;
DOpus.output(parentfolderName);
var result ="' +parentfolderName+ ' ([#]) ' +orginalext+ '" NUMBER=01;
return result;
}
if I write like this line it's works but I need to add a sequential Numbers after the file name
To alter the position of the numbering move "[#]" in the "New Name" field to after the \1
The " - " can be deleted if you don't want it, it's just for presentation
To adjust the number padding (how many places the sequential numbering has), add or remove zeroes from the first box under "Sequential numbering from:"
Thanks for the nice reply; I can understand your screenshot clearly, but I don't want to use the rename dialog box. Can you tell me how to do the same thing in the new Rename script function OnGetNewName(getNewNameData)? even I search the forum but don't find any example post.
Set your Rename up using the dialog, then save it as a preset. You can then run that preset from a button/hotkey without having to go through the dialog again.
Thanks dear Jon! Yes I completely know that; as I have said in my original post. but in this time I want solve this with he new Rename script function OnGetNewName(getNewNameData). can please give me some light on that how to set this kind of sequential number in this Rename script function OnGetNewName(getNewNameData).
Here is a script that does the same (do note I did not make this):
Option Explicit
Dim StartingNumber
Dim PadTo
' First number to try. Usually 1.
StartingNumber = 1
' Number of digits to pad the number to. For example, if PadTo
' is 3 then the script will generate 001, 002, 003, 004, etc..
PadTo = 3
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Function OnGetNewName(ByRef GetNewNameData)
Dim bAbsolutePath
Dim strNum
Dim strNewName
Dim strTryNewName
Dim strTryNewFullPath
Dim bNeedLoop
Dim num
Dim i
If PadTo < 1 Then
PadTo = 1
End If
num = StartingNumber
StartingNumber = StartingNumber + 1 ' increase for next time
strNewName = GetNewNameData.newname
' Work out if the new path is relative to the original path or if it's an absolute path.
' For example, a rename from * to C:\* would move files to the root of C:\
If strNewName = fs.GetAbsolutePathName(strNewName) Then
bAbsolutePath = True
Else
bAbsolutePath = False
End If
bNeedLoop = True
While bNeedLoop
' Remove any existing number and insert the new number at the beginning
strNum = CStr(num)
If Len(strNum) < PadTo Then
strNum = String(PadTo - Len(strNum), "0") & strNum
End If
for i = 1 to Len(strNum)
if Mid(strNewName, i, 1) < "0" or Mid(strNewName, i, 1) > "9" Then
Exit for
end if
Next
if i <= Len(strNum) + 1 And Mid(strNewName, i, 1) = " " Then
OnGetNewName = Right(strNewName, Len(strNewName) - i)
end if
strTryNewName = strNum & " " & strNewName
' If new name is the same as the old name, we don't need to do anything
if strTryNewName = GetNewNameData.item.name Then
bNeedLoop = False
else
' Work out the full path to the new filename.
If bAbsolutePath Then
strTryNewFullPath = strTryNewName
Else
strTryNewFullPath = fs.BuildPath(GetNewNameData.item.path, strTryNewName)
End If
' Check if the new filename already exists.
If fs.FileExists(strTryNewFullPath) Or fs.FolderExists(strTryNewFullPath) Then
'DOpus.OutputString "Already exists: " & strTryNewFullPath
num = num + 1
Else
strNewName = strTryNewName
'DOpus.OutputString "Generated name: " & strNewName
bNeedLoop = False
End If
end if
Wend
OnGetNewName = strNewName
End Function
Thanks evernessince
I have tried to study that script. but it's so hard for a nob. is this script used a While.....Wend loop. But inside that loop there is lots of conditional If and End If nested that is make this script hard to understand. There is Path Condition also.
But what I want to achieve is not so complex like this script. I have no path condition, no if the new filename already exists condition.
So I think there is a more easy solution for achieve my want. Can any one give some easy example code in JavaScript.
You said yourself, near the start of the thread, that you can do this without scripting.
If you're still this confused about scripting concepts, and can do the same thing without using scripting, why don't you just do that instead of asking for people to write the whole custom script exactly as you want for you? This is just a waste of other people's time and goodwill.
If you can't learn scripting yourself, that's fine; not everyone can. But you can't expect the forum to keep writing custom scripts to your exact specifications. If you can't write scripts yourself, do what everyone else does and make do with the functionality which doesn't require scripting. You can still get a lot done that way, even if it takes one or two extra clicks sometimes.