I Need Help With Changing File Extension!!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nicklz55
    New Member
    • Sep 2008
    • 1

    I Need Help With Changing File Extension!!!!

    okay, ive looked literally on google for a whole hour trying to find the code but it never works out properly.

    basically what i want is a textbox that the user enters the location of the file and then a button that when clicked it will change the file extension to .caf

    please reply with any type of help

    thanks!
  • vdraceil
    New Member
    • Jul 2007
    • 236

    #2
    Try this..

    Dim fso as new filesystemobjec t
    Dim f as file
    Private sub command1_click( )
    Set f = fso.getfile(pat h\filename)
    f.copy(path\fil ename.ext) 'any extension you wish
    End sub

    all you have to do is copy the file and save it with a different extension.you may also delete the original file with kill() function if you dont want it.
    Dont forget to add Microsoft scripting runtime to your project references.

    Comment

    • rpicilli
      New Member
      • Aug 2008
      • 77

      #3
      You'll need the following componentes in a form

      1 textbox
      2 buttoms
      1 Openfiledialog


      TextBox name = txtFileNameOri
      Buttom1 name = Buttom1
      Buttom2 name = butChangeFileEx tension
      OpenFileDialog = OpenFileDialog1

      How this works...


      1 - First you click of the Buttom1 that will open up the file dialog.
      2 - Choose a file no matter what is the extension an localization.
      3 - As soon as you close the file dialog, the complete path will be in text box.
      4 - Click over the buttom butCangeFileExt ension.
      5 - Three variable will be created (FileOri, FileDes, FileExt) means File Name Original, File Name Destination, File Extension).
      Each of will receive the correct names.
      File.move will rename the file extension once you keep the file name and change only the extension part.

      Hope this help you


      Rpicilli




      [CODE]


      Private Sub butChangeFileEx tension_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles butChangeFileEx tension.Click
      Dim FileOri, FileDes, fileExt As String
      'Save the orginal file name
      FileOri = Me.txtFileNameO ri.Text
      'Change the file extension
      fileExt = Me.txtFileNameO ri.Text.Substri ng(Me.txtFileNa meOri.Text.Last IndexOf("."))
      Me.txtFileNameO ri.Text = Me.txtFileNameO ri.Text.Replace (fileExt, ".caf")
      'Save the future file name
      FileDes = Me.txtFileNameO ri.Text
      Try
      File.Move(FileO ri, FileDes)
      Catch ex As Exception
      MessageBox.Show ("Error: " & ex.Message)
      End Try
      End Sub

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
      Me.OpenFileDial og1.ShowDialog( )
      Me.txtFileNameO ri.Text = Me.OpenFileDial og1.FileName
      End Sub


      /[CODE]

      Comment

      Working...