Projects

Find all our projects in development below.
All source code is GNU General Public License (GPL)

XBOX File Renamer

Browsing MainForm.frm (7.11 KB)

VERSION 5.00
Begin VB.Form MainForm 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "XBOX File Renamer"
   ClientHeight    =   2145
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   6150
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "MainForm.frx":0000
   MaxButton       =   0   'False
   ScaleHeight     =   2145
   ScaleWidth      =   6150
   StartUpPosition =   2  'CenterScreen
   Begin VB.Timer LoopTimer 
      Enabled         =   0   'False
      Interval        =   1
      Left            =   120
      Top             =   1080
   End
   Begin VB.CommandButton cmdStop 
      Caption         =   "&Close"
      Height          =   375
      Left            =   4680
      TabIndex        =   3
      Top             =   1320
      Width           =   1335
   End
   Begin VB.CommandButton cmdStart 
      Caption         =   "&Start"
      Height          =   375
      Left            =   3240
      TabIndex        =   2
      Top             =   1320
      Width           =   1335
   End
   Begin VB.Frame Frame1 
      Caption         =   "Directory of Files"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   120
      TabIndex        =   4
      Top             =   120
      Width           =   5895
      Begin VB.CommandButton cmdBrowse 
         Caption         =   "..."
         Height          =   315
         Left            =   5280
         Style           =   1  'Graphical
         TabIndex        =   1
         ToolTipText     =   "Browse for folder..."
         Top             =   360
         Width           =   375
      End
      Begin VB.TextBox txtDir 
         Height          =   315
         Left            =   240
         MaxLength       =   3000
         TabIndex        =   0
         Top             =   360
         Width           =   4935
      End
   End
   Begin VB.Label lblStatus 
      BackStyle       =   0  'Transparent
      BorderStyle     =   1  'Fixed Single
      Caption         =   " Ready."
      Height          =   255
      Left            =   0
      TabIndex        =   6
      Top             =   1920
      Width           =   6135
   End
   Begin VB.Label Label1 
      Caption         =   "Note: The XBOX file system (FAT-X) does not allow file names longer than 42 characters or certain special characters."
      Height          =   615
      Left            =   120
      TabIndex        =   5
      Top             =   1080
      Width           =   3015
   End
End
Attribute VB_Name = "MainForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Dim sFile As String
Dim lCount As Long
Dim lTotal As Long

Private Sub cmdBrowse_Click()
Dim sDir As String
    sDir = FolderBrowse(hWnd, "Browse for the directory of files to rename...")
    If sDir <> "" Then
        txtDir.Text = sDir
        txtDir.SelStart = 0
        txtDir.SelLength = Len(txtDir.Text)
        txtDir.SetFocus
    End If
End Sub

Private Sub cmdStart_Click()
    If Dir(txtDir.Text + "\") = "" Or txtDir.Text = "" Then
        MsgBox "Directory not found or directory contains no files.", vbExclamation
        txtDir.SelStart = 0
        txtDir.SelLength = Len(txtDir.Text)
        txtDir.SetFocus
        Exit Sub
    End If
    If Right(txtDir.Text, 1) <> "\" Then txtDir.Text = txtDir.Text + "\"
    cmdStart.Enabled = False
    cmdStop.Caption = "&Stop"
    txtDir.Enabled = False
    cmdBrowse.Enabled = False
    EnableX hWnd, False
    sFile = Dir(txtDir.Text)
    lCount = 0
    lTotal = 0
    LoopTimer.Enabled = True
End Sub

Private Sub cmdStop_Click()
    If LoopTimer.Enabled = True Then
        LoopTimer.Enabled = False
        cmdStart.Enabled = True
        cmdStop.Caption = "&Close"
        txtDir.Enabled = True
        cmdBrowse.Enabled = True
        EnableX hWnd, True
        lblStatus.Caption = " Ready."
    Else
        Unload Me
    End If
End Sub


Private Sub Form_Load()
    CButton cmdBrowse
End Sub



Private Sub LoopTimer_Timer()
Dim sNewFile As String
Dim sTemp As String
Dim lLen As Long
Dim iIncr As Integer
Dim iOpen As Integer
Dim iOpen1 As Integer
Dim iOpen2 As Integer
Dim iOpen3 As Integer
    If sFile = "" Then
        lblStatus.Caption = " Complete."
        MsgBox "The renaming process has completed." + vbCrLf + vbCrLf & lCount & " / " & lTotal & " files renamed.", vbInformation
        cmdStop_Click
        Exit Sub
    End If
    If sFile <> "." And sFile <> ".." And GetAttr(txtDir.Text + sFile) <> vbDirectory Then
        If Len(sFile) > 42 Then
            lblStatus.Caption = " Renaming " + sFile
            sNewFile = Replace(Replace(Replace(Replace(sFile, ",", "_"), "+", "_"), "<", "("), ">", ")")
            If InStr(sNewFile, ".") Then
                lLen = Len(sNewFile) - 42
                iOpen1 = InStr(sNewFile, "(")
                iOpen2 = InStr(sNewFile, "[")
                iOpen3 = InStr(sNewFile, "{")
                iOpen = iOpen1
                If iOpen2 < iOpen And iOpen2 > 0 Then iOpen = iOpen2
                If iOpen3 < iOpen And iOpen3 > 0 Then iOpen = iOpen3
                If iOpen < 4 Then iOpen = InStrRev(sNewFile, ".")
                sTemp = Mid(sNewFile, iOpen)
                sNewFile = Left(sNewFile, iOpen - lLen - 4) + "..." + sTemp
            Else
                sNewFile = Left(sNewFile, 39) + "..."
            End If
            Do While (FileEx(txtDir.Text + sNewFile) And iIncr <= 99)
                If sTemp = "" Then
                    sNewFile = Left(sNewFile, Len(sNewFile) - 2) & Format(iIncr, "00")
                Else
                    sNewFile = Replace(Replace(Replace(Replace(sFile, ",", "_"), "+", "_"), "<", "("), ">", ")")
                    sNewFile = Left(sNewFile, InStrRev(sNewFile, ".") - lLen - 4) + "." & Format(iIncr, "00") + sTemp
                End If
                iIncr = iIncr + 1
            Loop
            Name txtDir.Text + sFile As txtDir.Text + sNewFile
            lCount = lCount + 1
        Else
            sNewFile = Replace(Replace(Replace(Replace(sFile, ",", "_"), "+", "_"), "<", "("), ">", ")")
            If sFile <> sNewFile Then
                lblStatus.Caption = " Renaming " + sFile
                Name txtDir.Text + sFile As txtDir.Text + sNewFile
                lCount = lCount + 1
            Else
                lblStatus.Caption = " Skipping " + sFile
            End If
        End If
        lTotal = lTotal + 1
    End If
    sFile = Dir
End Sub


Download MainForm.frm

Back to file list


Back to project page