vbc.exeでフォルダを選択して、フォルダ内のファイル名の全角を半角にして、スペースがある場合は削除して一括リネームするソフトを作って
vbc.exe RenameFiles.vb /r:System.Windows.Forms.dll /r:System.Drawing.dll
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Module RenameFiles
' 全角文字を半角に変換する関数
Function ConvertFullWidthToHalfWidth(ByVal input As String) As String
Dim sb As New StringBuilder(input.Length)
For Each ch As Char In input
If (ch >= ChrW(&HFF01) AndAlso ch <= ChrW(&HFF5E)) Then
sb.Append(ChrW(AscW(ch) - &HFF00 + &H20))
ElseIf ch = ChrW(&H3000) Then
sb.Append(" ")
Else
sb.Append(ch)
End If
Next
Return sb.ToString().Replace(" ", "")
End Function
Sub Main()
Dim folderPath As String = SelectFolder()
If folderPath <> "" Then
Dim dirInfo As New DirectoryInfo(folderPath)
Dim files As FileInfo() = dirInfo.GetFiles()
For Each file As FileInfo In files
Dim newFileName As String = ConvertFullWidthToHalfWidth(file.Name)
Dim newFilePath As String = Path.Combine(folderPath, newFileName)
Try
File.Move(file.FullName, newFilePath)
Console.WriteLine($"リネームしました: {file.Name} -> {newFileName}")
Catch ex As Exception
Console.WriteLine($"エラーが発生しました {file.Name}: {ex.Message}")
End Try
Next
Else
Console.WriteLine("フォルダが選択されていません。")
End If
End Sub
' フォルダを選択する関数
Function SelectFolder() As String
Dim fbd As New FolderBrowserDialog()
If fbd.ShowDialog() = DialogResult.OK Then
Return fbd.SelectedPath
Else
Return ""
End If
End Function
End Module