Re: Smarter rename
Posted: 2018 Dec 28, 20:14
As it sounds like you might be looking to improving mass renaming I want to mention again I desperately want Case changing and a Trim function. This seems to come up a lot with me.
As it sounds like you might be looking to improving mass renaming I want to mention again I desperately want Case changing and a Trim function. This seems to come up a lot with me.
Code: Select all
>I:\MISC\wscript I:\MISC\CreateNewFolder.vbs "$P"
Code: Select all
' VB Script Document
option Explicit
'===========================================================================================
' CreateNewFolder.vbs
' Requires XPLORER2 - run as a user command with the syntax:
' wscript {path}\CreateNewFolder.vbs "$P"
'
' Uses the string captured in the clipboard and creates a folder in the current active pane.
' Features:
' - Removed invalid characters from the folder name and substitutes per a predetermined list
' - Changes the folder name to Title Case
' - Checks for same named folder before creating a new folder.
'===========================================================================================
' COMMON VARIABLES
Dim fso, Wsh, RootFolder, DEBUGG
' MAIN
Dim MainFolder, fldr, objHTML, exists, f, CBText, FullFileName
' strClean
Dim tempstr, charArray, tmpChar, changeTo, i
'===== SET GLOBALS =====
' Uncomment "true" to get messages during execution for debugging
' DEBUGG = True
DEBUGG = False
'================================================================'
' begin program '
'================================================================'
' create common objects'
Set fso = CreateObject("Scripting.FileSystemObject")
Set Wsh = WScript.CreateObject("WScript.Shell")
RootFolder = "{BLANK}"
If WScript.Arguments.Count > 0 Then
RootFolder = WScript.Arguments.Item(0)
If DEBUGG Then MsgBox "RootFolder = " & RootFolder
Main
Else ' SCRIPT ENDS WITHOUT EXECUTING
MsgBox "NO VARIABLES ON COMMANDLINE FOR ROOTFOLDER"
End If
' CLEANUP
Set fso = Nothing
Set Wsh = Nothing
'================================================================'
Sub Main
Set MainFolder = fso.GetFolder(RootFolder)
' Get clipboard text
Set objHTML = CreateObject("htmlfile")
CBText = objHTML.ParentWindow.ClipboardData.GetData("text")
If CBText = "" Then
MsgBox "Nothing in CLIPBOARD"
Exit Sub
End If
If DEBUGG Then MsgBox CBText
FullFileName = RootFolder & "\" & strClean (CBText)
If DEBUGG Then MsgBox "FullFileName = " & FullFileName
exists = fso.FolderExists(FullFileName)
If (exists) Then
MsgBox "Folder " & FullFileName & " already exists!", vbOKOnly+vbExclamation, "Folder Creation Error"
Else
If DEBUGG Then
MsgBox "New folder is " & FullFileName & vbCRLF & " (not created in DEBUGG mode)"
Else
Set f = fso.CreateFolder(FullFileName)
End If
End If
' cleanup
Set MainFolder = Nothing
Set f = NOTHING
Set objHTML = Nothing
End Sub
Function strClean (strtoclean)
Dim charArray
tempstr = strtoclean
charArray = Array("?", "/", "\", ":", "*", """", "<", ">", "|")
For Each tmpChar in charArray
Select Case tmpChar
Case "/", "\"
changeTo = "-"
Case ":"
changeTo = " -"
Case "<"
changeTo = "["
Case ">"
changeTo = "]"
Case Else
changeTo = ""
End Select
tempstr = replace( tempstr, tmpChar, changeTo )
Next
strClean = TCase (tempstr) ' = tempstr
End Function
Function TCase(strTextString)
'Convert string to Title Case
Dim arrTextItem, strTextNew, strSplitText, strSplitItem, y, x
strSplitText = " '-"
For y = 1 to len(strSplitText)
strSplitItem = Mid(strSplitText,y,1)
arrTextItem = Split(strTextString, strSplitItem)
For x = 0 to Ubound(arrTextItem)
If strSplitItem = "'" Then
If Mid(arrTextItem(x),2,1) = " " Then
strTextNew = strTextNew & strSplitItem & LCase(Left(arrTextItem(x),1)) & Right(arrTextItem(x),Len(arrTextItem(x))-1)
Else
strTextNew = strTextNew & strSplitItem & UCase(Left(arrTextItem(x),1)) & Right(arrTextItem(x),Len(arrTextItem(x))-1)
End If
Else
If strSplitItem = "-" Then
strTextNew = strTextNew & strSplitItem & UCase(Left(arrTextItem(x),1)) & Right(arrTextItem(x),Len(arrTextItem(x))-1)
Else
strTextNew = strTextNew & strSplitItem & UCase(Left(arrTextItem(x),1)) & LCase(Right(arrTextItem(x),Len(arrTextItem(x))-1))
End If
End If
Next
strTextString = Right(strTextNew,Len(strTextNew)-1)
strTextNew = ""
Next
TCase = strTextString
End Function
I did not know this. Thanks, Nikos!
2 things.
Could not find mention of this in the Help PDF. The documentation exists in the online manual, the program folder's version at x2Help.htm#ma_renwiz, and in this thread.mass rename has the character range construct $[3:2] that specifies starting position and length
Code: Select all
Control with Focus | Responds to Alt+R
---------------------|------------------
Mode | RE checkbox
Preserve extension | RE checkbox
RE checkbox | Rename button
What to match | RE checkbox
Target name template | Rename button
Preview button | Rename button
Special tokens | Rename button
Old name / New name | Rename button
$-Token help | Rename button
Rename button | RE checkbox
Cancel button | Rename button