QA@IT
«回答へ戻る

回答を投稿

VBSを使った方法です。
fs.GetFolderの部分を適切なフォルダーにするとよいかと思います。

Dim fs
Dim folder
Dim files
Dim OldName
Dim NewName

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder("D:\work")
set files = folder.Files
For Each file in files
    OldName =file.Name
    NewName = TransFileName(OldName)
    if OldName <> NewName then
        file.Move file.ParentFolder & "\" & NewName 
    end if
Next

Function TransFileName(OldName)
    Dim NewName
    Dim NameParts
    Dim UBParts
    Dim Idx
    Dim tmp 

    NameParts = Split(OldName,"_")
    UBParts =UBound(NameParts)

    If UBParts <= 0 Then
        NewName =OldName
    Else
        NewName = NameParts(0)
        For Idx = 1 To UBParts
           NewName = NewName & "_"
           tmp = NameParts(Idx)
           If Len(tmp)<2 Then
               NewName = NewName & tmp
           Else
               NewName = NewName & UCase(Mid(tmp, 1, 1)) & Mid(tmp, 2)
           End If
        Next
    End If

    TransFileName = NewName
End Function

VBSを使った方法です。
`fs.GetFolder`の部分を適切なフォルダーにするとよいかと思います。

```
Dim fs
Dim folder
Dim files
Dim OldName
Dim NewName

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder("D:\work")
set files = folder.Files
For Each file in files
    OldName =file.Name
    NewName = TransFileName(OldName)
    if OldName <> NewName then
        file.Move file.ParentFolder & "\" & NewName 
    end if
Next

Function TransFileName(OldName)
    Dim NewName
    Dim NameParts
    Dim UBParts
    Dim Idx
    Dim tmp 

    NameParts = Split(OldName,"_")
    UBParts =UBound(NameParts)

    If UBParts <= 0 Then
        NewName =OldName
    Else
        NewName = NameParts(0)
        For Idx = 1 To UBParts
           NewName = NewName & "_"
           tmp = NameParts(Idx)
           If Len(tmp)<2 Then
               NewName = NewName & tmp
           Else
               NewName = NewName & UCase(Mid(tmp, 1, 1)) & Mid(tmp, 2)
           End If
        Next
    End If

    TransFileName = NewName
End Function

```