I tested many many times ruining your great work, finally I got just what I wanted.
But, as you see, it's very stupid way. 
I never studied programming things before and even English isn't my first language.
Could you Fix my stupid work? 
@script vbscript
option explicit
' ************************** Script Information **************************
' From file rename script version 3.0
' (tested with Directory Opus 9.5.6.0)
' by Henrik Ripa (gieron@yahoo.com) 2010-12-17
' ************************************************************************
' ****************************** Changelog *******************************
' Version 3.0
' + Will now get text from the clipboard if there are no text files to use
' + Now supports text files in UTF-8 and UTF-16 (LE and BE) if they have
' a correct BOM (Byte Order Mark)
' + Added an option to read lines in reverse order
' + The default regexp works better for file names with dots in them
' Version 2.1
' + Better regexp that works for renaming of directories and files
' without extension.
' + Will now remove characters that are illegal in filenames.
' + Now looks for a 'Clipboard Text.txt' file if the 'filenames.txt'
' file is missing.
' Version 2.0
' + Rewritten to use magic markers in new filenames.
' Version 1.0
' + Initial version. Worked entirely differently.
' ************************************************************************
' ***************************** Installation *****************************
' Download the .orp file. Open the Directory Opus rename dialog and set
' it to advanced mode. Select import from the file menu and open the .orp
' file. You can then add it to the presets with the add button. I suggest
' using the name From File but you can call it anything you want.
' ************************************************************************
' **************************** Instructions ******************************
' This script replaces the string 'FROMFILE' in new file names with lines
' taken from a user created text file or from the clipboard. If the lines
' include any characters that are illegal in filenames they will be
' removed.
'
' By default the text file the script looks for must have the name
' 'filenames.txt' or 'Clipboard Text.txt'. The latter is the default name
' DOpus uses when you paste text content into a lister. The text file
' must be located in the same directory as the files you want to rename.
'
' When the text file is in place, or you have copied some text to the
' clipboard, select the files you want to rename. The order of the
' selected files in the lister must be the same as the order in the text
' file. Then click the rename button and select this script under presets.
'
' Set up the old name and new name fields so that the the string
' 'FROMFILE' is present in the new file names. You can use standard
' rename, regular expressions or find and replace. Inspect the results
' in the preview pane and click OK.
'
' If you have problems you can start by examining the script tab in the
' Directory Opus output window. The script outputs a lot of information
' there. If you find a bug or have a feature request you can either go to
' the Dopus Resource Centre forum thread where you got this script from
' or send me an email.
' ************************************************************************
' ******************************* Options ********************************
dim optReverseOrder, optFileNames, optMagicMarker, optIllegalReplacement
dim optIllegalCharacters, optUseEmptyLines
' If this is true the file names from the file, or from clipboard,
' will be read in reverse order
optReverseOrder = False
' List of files to read file names from, can be empty if you only want
' to use text from the clipboard
optFileNames = Array("filenames.txt", "Clipboard Text.txt")
' Magic marker to replace with names from file
optMagicMarker = "FROMFILE"
' What to replace illegal file name characters with
optIllegalReplacement = ""
' Pattern of illegal file name characters
optIllegalCharacters = "[/\\:*?<>\|""]"
' Whether to use empty lines in the source or not
optUseEmptyLines = False
' ************************************************************************
' ************************ DOpus rename function *************************
' This is the function that is called by DOpus to get a new file name,
' it is called once for each file that will be renamed
Function Rename_GetNewName _
( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )
dorInitialize strFilePath
strNewName = dorGetNewName(strFileName, strNewName)
End Function
' ************************************************************************
' ********************* Directory Opus rename module *********************
dim dorInitialized
dorInitialized = False
' Initalizes the module by initializing all the modules it depends on
Function dorInitialize( strPath )
' Only run this initialization once
if (dorInitialized) then exit function
dorInitialized = True
' Print script identification
eioPrint "From file rename script by Henrik Ripa"
' Initialize the file names source and remove illegal character modules
fnsInitialize strPath, optFileNames, optReverseOrder
ricInitialize optIllegalCharacters, optIllegalReplacement
End Function
' Returns the new name for the given file, the input is the files old
' name and the name it gets after the preprocessing that is done in DOpus
Function dorGetNewName( strOldName, strMidName )
dim line
' Set new name to the original name to undo the preprocessing
' in case we do not come up with a new name
dorGetNewName = strOldName
' Exit if there are nothing to rename with
if (fnsNoMoreNames()) then exit function
' Ignore anything that does not have the magic marker
if (instr(strMidName, optMagicMarker) = 0) then exit function
' Ignore the filenames file if the user has selected it
if (strOldName = focGetUsedFile()) then exit function
' Get next file name from source
line = fnsGetNextName()
' Clean file name from unwanted characters
line = ricReplaceCharacters(line)
' Assemble new file name, if it isn't empty
if (optUseEmptyLines or line <> "") then
dorGetNewName = Replace(strMidName, optMagicMarker, line)
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
if (fnsGetNextName = "") then exit function
end if
End Function
' ************************************************************************
' ****************** Replace illegal characters module *******************
dim ricRegexp, ricReplacement
' Takes arguments for the module and creates the regexp object
Function ricInitialize( strPattern, strReplacement )
set ricRegexp = new Regexp
ricRegexp.Global = True
ricRegexp.IgnoreCase = False
ricRegexp.Pattern = strPattern
ricReplacement = strReplacement
End Function
' Replaces illegal characters in the text with the replacement string
Function ricReplaceCharacters( strText )
dim text
text = ricRegexp.Replace(strText, ricReplacement)
if (strText <> text) then
eioPrint "Replaced illegal characters in """ & strText & """"
end if
ricReplaceCharacters = text
End Function
' ************************************************************************
' *********************** File names source module ***********************
dim fnsSourceLines, fnsCurrentLine
' Initializes the file names source by getting the source text
' from file or clipboard
Function fnsInitialize( strPath, arrFileNames, bolReverseOrder )
dim lines, text
fnsCurrentLine = 0
text = focGetText(strPath, arrFileNames)
lines = arhSplitString(text)
if (bolReverseOrder) then
lines = arhRemoveLastIfEmpty(lines)
lines = arhReverse(lines)
end if
fnsSourceLines = lines
End Function
' Returns true if there are no lines left, i.e. if the source text
' is empty or non existant or if all lines have been returned,
' false otherwise
Function fnsNoMoreNames( )
dim nomore
nomore = (fnsCurrentLine > Ubound(fnsSourceLines))
if (nomore) then
eioPrint "No more names in source text"
end if
fnsNoMoreNames = nomore
End Function
' Returns the next line from the source text
Function fnsGetNextName( )
if (fnsCurrentLine > Ubound(fnsSourceLines)) then
fnsGetNextName = ""
else
fnsGetNextName = fnsSourceLines(fnsCurrentLine)
fnsCurrentLine = fnsCurrentLine + 1
end if
End Function
' ************************************************************************
' *********************** File or clipboard module ***********************
dim focFileNameUsed
' Reads text from files in the given string array or from clipboard,
' it will return the first one that has content
Function focGetText( strPath, arrFileNames )
dim file, text
focFileNameUsed = ""
for each file in arrFileNames
text = focGetTextFromFile(strPath & "\" & file)
if (text <> "") then
focFileNameUsed = file
eioPrint "Using the file '" & file & "' as source text"
exit for
end if
next
if (text = "") then
text = focGetTextFromClipboard()
if (text <> "") then
eioPrint "Using the clipboard as source text"
else
eioPrint "No files and nothing in clipboard to use as source text"
end if
end if
focGetText = text
End Function
' Returns the file name used for getting the text, if any
Function focGetUsedFile( )
focGetUsedFile = focFileNameUsed
End Function
' Reads text from clipboard
Function focGetTextFromClipboard( )
dim hto, text
set hto = CreateObject("htmlfile")
text = hto.parentwindow.clipboardData.GetData("text")
if (VarType(text) <> vbString) then text = ""
focGetTextFromClipboard = text
End Function
' Reads text from file, supports UTF-8, UTF-16 and UTF-16 (BE) files
' with proper BOM (Byte Order Mark)
Function focGetTextFromFile( strTextFile )
dim ado, fso, tmp, bom(3), encoding, file, i
const adTypeBynary = 1
const adTypeText = 2
const adReadAll = -1
on error resume next
set ado = CreateObject("ADODB.Stream")
ado.Open
ado.Type = adTypeBynary
ado.LoadFromFile strTextFile
tmp = ado.Read(3)
for i = 0 To 2
bom(i) = AscB(MidB(tmp, i+1, 1))
next
ado.Close
if err.number > 0 then
focGetTextFromFile = ""
else
if (bom(0) = &hEF and bom(1) = &hBB and bom(2) = &hBF) then
encoding = "utf-8" ' UTF-8
elseif (bom(0) = &hFE and bom(1) = &hFF) then
encoding = "unicode" ' UTF-16 big endian
elseif (bom(0) = &hFF and bom(1) = &hFE) then
encoding = "unicodeFFFE" ' UTF-16 little endian
else
encoding = "default"
end if
eioPrint "Loading file using " & encoding & " encoding"
if (encoding = "default") then
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.OpenTextFile(strTextFile, 1, False)
if err.number > 0 then
focGetTextFromFile = ""
else
focGetTextFromFile = file.ReadAll()
end if
else
set ado = CreateObject("ADODB.Stream")
ado.Open
ado.Type = adTypeText
ado.CharSet = encoding
ado.LoadFromFile strTextFile
if err.number > 0 then
focGetTextFromFile = ""
else
focGetTextFromFile = ado.ReadText(adReadAll)
end if
end if
end if
End Function
' ************************************************************************
' ************************* Array helper module **************************
' Splits a string into an array of strings on line breaks (\r\n, \r or \n)
Function arhSplitString( strText )
dim text
text = strText
text = Replace(text, vbCrLf, vbLf)
text = Replace(text, vbCr, vbLf)
arhSplitString = Split(text, vbLf)
End Function
' Returns an array that is in reverse order to the input array
Function arhReverse( ByVal arrIn )
dim index, maxIndex, out
maxIndex = Ubound(arrIn)
if (maxIndex < 1) then
arhReverse = arrIn
exit function
end if
redim out(maxIndex)
for index = 0 to maxIndex
out(maxIndex - index) = arrIn(index)
next
arhReverse = out
End Function
' Returns an array where the last element of the input array has
' been removed if it was an empty string
Function arhRemoveLastIfEmpty( ByVal arrIn )
dim index, maxIndex, out
maxIndex = Ubound(arrIn)
if (maxIndex > -1) then
if (arrIn(maxIndex) = "") then
maxIndex = maxIndex - 1
redim out(maxIndex)
for index = 0 to maxIndex
out(index) = arrIn(index)
next
arhRemoveLastIfEmpty = out
else
arhRemoveLastIfEmpty = arrIn
end if
else
arhRemoveLastIfEmpty = arrIn
end if
End Function
' ************************************************************************
' ****************** Error & information output module *******************
' Prints message to the appropriate output channel
Function eioPrint( strMessage )
Dopus.OutputString strMessage
'WScript.Echo strMessage
End Function
' ************************************************************************