In my personal documents I'm using a sort of Naming Convention where all my files are named as follows yyyy-mm-dd-FileName.xyz
I would like your support on how to develop a VBScript that can:
Can someone help me to finish the code below? The idea is use Regular Expression to identify spaces and accented characters and rename the files.
- The first characters refer to the Last Modified Date that in many cases represent the Creation Date of the file.
- ".xyz" I don't change it because it is the file extension.
- I don't keep spaces or any special character such as accents or accented characters.
I would like your support on how to develop a VBScript that can:
- Remove all spaces of the name by replacing it by "-" Character
- Replace Accents & Accented Characters for English Equivalent character
- Verify if the first 11 Characters of the File Name is following the Rule of the Naming Convention yyyy-mm-dd- based on Last Modified date of the file. If NOT then rename it as per my Naming Convention yyyy-mm-dd-FileName.xyz
Can someone help me to finish the code below? The idea is use Regular Expression to identify spaces and accented characters and rename the files.
VBA Code:
Option Explicit
Dim FSO As Object, WindowsFolder As Object, FolderFiles As Object, FoundFile As Object
Dim RegularExpression As Object
Dim TargetFolder As String
Sub RenameFilesAsPerCriteria()
Set FSO = CreateObject("Scripting.FileSystemObject")
TargetFolder = "C:\Users\Juliano\Documents\MrExcelForumExample"
Set WindowsFolder = FSO.GetFolder(TargetFolder)
Set FolderFiles = WindowsFolder.Files
Set RegularExpression = New RegExp
RegularExpression.Global = True
'RegularExpression.Pattern = white spaces, Accents & Accented Characters
For Each FoundFile In FolderFiles
If RegularExpression.Test(FoundFile.Name) = True Then
'1-Remove Whitespaces replacing it by "-" character
'2-Replace Accents & Accented Characters for English Equivalent character
'3-Verify if the file name contains the file name convention yyyy-mm-dd-FileName.xyz
' if NOT rename the file accordingly
Else: End If
Next
VerifySubFolders FSO.GetFolder(TargetFolder)
End Sub
Sub VerifySubFolders(Folder)
Dim Subfolder As Object
For Each Subfolder In Folder.SubFolders
Set WindowsFolder = FSO.GetFolder(Subfolder.Path)
Set FolderFiles = WindowsFolder.Files
Set RegularExpression = New RegExp
RegularExpression.Global = True
RegularExpression.Pattern = white spaces, Accents & Accented Characters
For Each FoundFile In FolderFiles
If RegularExpression.Test(FoundFile.Name) = True Then
'1-Remove Whitespaces replacing it by "-" character
'2-Replace Accents & Accented Characters for English Equivalent character
'3-Verify if the file name contains the file name convention yyyy-mm-dd-FileName.xyz
' if NOT rename the file accordingly
Else: End If
Next
VerifySubFolders Subfolder
Next
End Sub