I am using this code to trim filenames. I cannot figure out how to expand this to trim ALL files in the folder after the first SPACE from the left in the filename.
My Code:
Code:
Before: 41-010 Rev A.txt
After: 41-010.txt
My Code:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Scripts'} Where " & "ResultClass = CIM_DataFile")
For Each objFile In colFiles
strPath = objFile.Drive & objFile.Path
strExtension = objFile.Extension
strFileName = objFile.FileName
If Right(strFileName, 1) = "A" Then
intLength = Len(strFileName)
strFileName = Left(strFileName, intLength - 6)
End If
strNewName = strPath & strFileName & "." & strExtension
errResult = objFile.Rename(strNewName)
Next