Connecting Tech Pros Worldwide Forums | Help | Site Map

Chaning a file's extension

Newbie
 
Join Date: Mar 2009
Posts: 16
#1: Jul 31 '09
I'm writing an import application that import .csv files into my SQL Server 2005 database. When the import is complete I need to change that files extension from .csv to .imp with the same path. I've tried using the following:

FileSystem.Rename(fullpathofoldfile, fullpathofnewfile)
Microsoft.VisualBasic.Rename(foldfile, fullpathofnewfile)
My.Computer.FileSystem.RenameFile(foldfile, fullpathofnewfile)

All attempts are giving back an error or 'Procedure or argument is invalid'. I have full access and permission to all files in all paths.

MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 283
#2: Jul 31 '09

re: Chaning a file's extension


Hi, this might not be the most elegant solution, but it sure works:

Expand|Select|Wrap|Line Numbers
  1. Dim Path As String = "C:\"
  2. Dim strFileName As String = "test.csv"
  3. strFileName = strFileName.Replace(".csv", "")
  4. My.Computer.FileSystem.RenameFile(Path & strFileName & ".txt", strFileName & ".imp")
Steven
Reply

Tags
file extensions