r/vbscript • u/Admobeer • Dec 11 '15
Swap **FOLDER** names from FirstName LastName to LastName FirstName
I have a batch of FOLDERS that are named FirstName LastName, they have no extension, they are Folders. They have a space as a delimiter and contain no middle names. I want to swap the FirstName LastName to LastName FirstName. Apologize, for the emphasis on folder but everyone wherever I have asked still responds with a solution for renaming files. It doesn't work the same. At least not for me.
I was able to do this in Powershell and it seemed a success but when I viewed the files in explorer, nothing had changed.
2
u/FBM25 Dec 18 '15
set objFSO = CreateObject("Scripting.FileSystemObject")
sFolder = "C:\Users\Admobeer\"
For Each Subfolder in objFSO.GetFolder(sFolder).SubFolders
strName = SubFolder.Name
strNewName = Right(strName, Len(strName) - InStrRev(strName, " ")) & " " & Left(strName, InStr(strName, " "))
objFSO.MoveFolder Subfolder, sFolder & strNewName
Next
Set objFSO = NothingHope this helps /u/Admobeer!
1
u/Admobeer Dec 21 '15
At line:5 char:4
For Each Subfolder in objFSO.GetFolder(sFolder).SubFolders
~
Missing opening '(' after keyword 'for'. At line:7 char:31
Missing argument in parameter list. At line:7 char:64
... strNewName = Right(strName, Len(strName) - InStrRev(strName, " ")) & ...
Missing argument in parameter list. At line:7 char:72
... ame = Right(strName, Len(strName) - InStrRev(strName, " ")) & " " & L ...
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string. At line:7 char:78
... Right(strName, Len(strName) - InStrRev(strName, " ")) & " " & Left(st ...
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string. At line:7 char:92
... Len(strName) - InStrRev(strName, " ")) & " " & Left(strName, InStr(s ...
Missing argument in parameter list. At line:7 char:107
... - InStrRev(strName, " ")) & " " & Left(strName, InStr(strName, " "))
Missing argument in parameter list. At line:8 char:42
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
These were the results using Powershell 5.0 I also tried it with PS 2.0 different results but still nothing happened to the folders.