I get a filename and then i want to make changes to it and then save that file to its new name. anyone have some suggestions? thanks
Printable View
I get a filename and then i want to make changes to it and then save that file to its new name. anyone have some suggestions? thanks
Hello,
Try the following code,
Hope it helps,Code:Option Explicit
Private Sub Command1_Click()
Name "c:\oldname.txt" As "c:\newname.txt"
End Sub
Desire.
thanks, i knew there was an easy way, i had done it before, but i lost that program when my drive crashed so i couldnt check it. thanks though
You might want to first check to see if newname.txt already exists. You can do that by using the following Property Get as an example.
g_sSepDir$ is defined asCode:Public Property Get FileExists(ByVal sPathname As String) As Boolean
'***************************************************************************
'Purpose: Determines whether the specified file exists
'Input: sPathName - file to check for
'Output: True if file exists, False otherwise
'***************************************************************************
Dim nFileNum As Integer
On Error Resume Next
'
' If the string is quoted, remove the quotes.
'
sPathname = UnQuoteString(sPathname)
'
'Remove any trailing directory separator character
'
If Right$(sPathname, 1) = g_sSepDir Then
sPathname = Left$(sPathname, Len(sPathname) - 1)
End If
'
'Attempt to open the file, return value of this function is False
'if an error occurs on open, True otherwise
'
nFileNum = FreeFile
Open sPathname For Input As nFileNum
FileExists = IIf(Err = 0, True, False)
Close nFileNum
Err = 0
Exit Property
ErrorRoutine:
Err.Raise genUnknownError, "CUtil::FileExists", Err.Description
End Property
Private Const g_sSepDir$ = "\"