home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Bulk_Renam21321010272008.psc / Form1.frm < prev    next >
Text File  |  2008-10-27  |  6KB  |  209 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Renanmer"
  5.    ClientHeight    =   7470
  6.    ClientLeft      =   45
  7.    ClientTop       =   435
  8.    ClientWidth     =   8040
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   7470
  13.    ScaleWidth      =   8040
  14.    StartUpPosition =   2  'CenterScreen
  15.    Begin VB.TextBox Text1 
  16.       BackColor       =   &H8000000F&
  17.       Height          =   2535
  18.       Left            =   2520
  19.       Locked          =   -1  'True
  20.       MultiLine       =   -1  'True
  21.       ScrollBars      =   3  'Both
  22.       TabIndex        =   3
  23.       Top             =   2040
  24.       Width           =   5415
  25.    End
  26.    Begin VB.TextBox Text4 
  27.       BackColor       =   &H80000010&
  28.       ForeColor       =   &H000000FF&
  29.       Height          =   2415
  30.       Left            =   2520
  31.       Locked          =   -1  'True
  32.       MultiLine       =   -1  'True
  33.       ScrollBars      =   3  'Both
  34.       TabIndex        =   9
  35.       Top             =   4920
  36.       Width           =   5415
  37.    End
  38.    Begin VB.CommandButton Command1 
  39.       Caption         =   "Rename"
  40.       Height          =   375
  41.       Left            =   2520
  42.       TabIndex        =   8
  43.       Top             =   1320
  44.       Width           =   5415
  45.    End
  46.    Begin VB.TextBox Text3 
  47.       Height          =   285
  48.       Left            =   2520
  49.       TabIndex        =   5
  50.       Top             =   960
  51.       Width           =   5415
  52.    End
  53.    Begin VB.TextBox Text2 
  54.       Height          =   285
  55.       Left            =   2520
  56.       TabIndex        =   4
  57.       Top             =   360
  58.       Width           =   5415
  59.    End
  60.    Begin VB.DriveListBox Drive1 
  61.       Height          =   315
  62.       Left            =   120
  63.       TabIndex        =   2
  64.       Top             =   120
  65.       Width           =   2295
  66.    End
  67.    Begin VB.DirListBox Dir1 
  68.       Height          =   3240
  69.       Left            =   120
  70.       TabIndex        =   1
  71.       Top             =   480
  72.       Width           =   2295
  73.    End
  74.    Begin VB.FileListBox File1 
  75.       Height          =   3600
  76.       Left            =   120
  77.       TabIndex        =   0
  78.       Top             =   3800
  79.       Width           =   2295
  80.    End
  81.    Begin VB.Label Label5 
  82.       Alignment       =   1  'Right Justify
  83.       AutoSize        =   -1  'True
  84.       Caption         =   "Files"
  85.       Height          =   195
  86.       Left            =   7560
  87.       TabIndex        =   12
  88.       Top             =   1800
  89.       Width           =   315
  90.    End
  91.    Begin VB.Label Label4 
  92.       AutoSize        =   -1  'True
  93.       Caption         =   "Error(s):"
  94.       Height          =   195
  95.       Left            =   2520
  96.       TabIndex        =   11
  97.       Top             =   4680
  98.       Width           =   540
  99.    End
  100.    Begin VB.Label Label3 
  101.       Caption         =   "Status"
  102.       Height          =   195
  103.       Left            =   2520
  104.       TabIndex        =   10
  105.       Top             =   1800
  106.       Width           =   450
  107.    End
  108.    Begin VB.Label Label2 
  109.       AutoSize        =   -1  'True
  110.       Caption         =   "Replace with:"
  111.       Height          =   195
  112.       Left            =   2520
  113.       TabIndex        =   7
  114.       Top             =   720
  115.       Width           =   975
  116.    End
  117.    Begin VB.Label Label1 
  118.       AutoSize        =   -1  'True
  119.       Caption         =   "Find text in FileName:"
  120.       Height          =   195
  121.       Left            =   2520
  122.       TabIndex        =   6
  123.       Top             =   120
  124.       Width           =   1515
  125.    End
  126. End
  127. Attribute VB_Name = "Form1"
  128. Attribute VB_GlobalNameSpace = False
  129. Attribute VB_Creatable = False
  130. Attribute VB_PredeclaredId = True
  131. Attribute VB_Exposed = False
  132. Private Sub Command1_Click()
  133. On Error GoTo Err:
  134. Text1.Text = "Selected Directory: " & Dir1.Path
  135. Text4.Text = ""
  136. Dim FileLen, FindTxt, Before, After, OldName, NewName
  137.  
  138. 'start loop
  139. For a = 0 To File1.ListCount - 1
  140.  
  141. ' Count total number of characters in the selected file
  142. FileLen = Len(File1.List(a))
  143.  
  144. 'Check whether the selected file contains the Find text
  145. FindTxt = InStr(1, File1.List(a), Text2.Text)
  146.  
  147. 'If Selected file contains the given find text then rename it
  148. If FindTxt <> 0 Then
  149.  
  150. 'part of file name before the given find text
  151. Before = Left(File1.List(a), FindTxt - 1)
  152.  
  153. 'part of file name after the given find text
  154. After = Right(File1.List(a), FileLen - Len(Text2.Text) - Len(Before))
  155.  
  156. 'Old file name
  157. OldName = Dir1.Path & "\" & File1.List(a)
  158.  
  159. 'Nem file name
  160. NewName = Dir1.Path & "\" & Before & Text3.Text & After
  161.  
  162. 'Rename the files in the selected folder
  163. Name OldName As NewName
  164.  
  165. 'Write in the status box when file name is changed
  166. Text1.Text = Text1.Text & vbCrLf & a & ": File Rename As: " & Before & Text3.Text & After
  167.  
  168. Else
  169.  
  170. 'If Selected file does not contain the given find text then write in error box
  171. Text4.Text = Text4.Text & vbCrLf & a & ": File Can not Rename: " & File1.List(a)
  172.  
  173. End If
  174.  
  175. Next
  176.  
  177. 'Rename completed
  178. Text1.Text = Text1.Text & vbCrLf & "Renaming Successfully Completed..."
  179.  
  180. 'When there is no error found.
  181. If Text4.Text = "" Then
  182. Text4.Text = "No error found. "
  183. End If
  184. File1.Refresh
  185. perr:
  186. Screen.MousePointer = vbDefault
  187. Exit Sub
  188.  
  189. Err:
  190. Text4.Text = Err.Description
  191. Resume perr:
  192.  
  193. End Sub
  194.  
  195. Private Sub Dir1_Change()
  196. 'display the files contain in the selected folder.
  197. File1.Path = Dir1.Path
  198. ' Count total number of files in the selected folder
  199. Label5.Caption = File1.ListCount & " File(s) in the selcted folder"
  200. End Sub
  201.  
  202. Private Sub Drive1_Change()
  203. Dir1.Path = Drive1.Drive
  204. End Sub
  205.  
  206. Private Sub Form_Load()
  207. Label5.Caption = File1.ListCount & " File(s) in the selcted folder"
  208. End Sub
  209.