File Rename in VB6

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


17 points

I have the following code in VB6 and I want to change the file extension of all .fin files to .txt. I used the code below to change the extension of all .fin files to .txt. But, the code below is changing the extension of files with no extension as well.

Dim fso As New FileSystemObject
Dim fil As Variant
 
For Each fil In fso.GetFolder(txtsourcedatabase).Files
  If (LCase$(fso.GetExtensionName(fil.Name)) = "fin") Or _
      (fso.GetExtensionName(fil.Name) = vbNullString) Then
    fso.MoveFile fil.Path, fso.BuildPath(fso.GetParentFolderName(fil.Path), _
      fso.GetBaseName(fil.Path) & ".txt")
  End If
Next



4 points

This one is simple. Remove the check for NULL from your IF in the code:

Dim fso As New FileSystemObject
Dim fil As Variant
 
For Each fil In fso.GetFolder(txtsourcedatabase).Files
  If (LCase$(fso.GetExtensionName(fil.Name)) = "fin") Then
    fso.MoveFile fil.Path, fso.BuildPath(fso.GetParentFolderName(fil.Path), _
      fso.GetBaseName(fil.Path) & ".txt")
  End If
Next

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.