VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



File Renaming

by SEBUANO, leonard bryan b. (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 30th May 2009
Date Added: Mon 8th February 2021
Rating: (1 Votes)

File Renaming

Rate File Renaming



'Add a Textbox and a Command button

Private Sub Command1_Click()
    Dim Path$
    Dim oFile$, nFile$
    
    Path$ = "D:\"
    oFile$ = "SAMPLE.TXT"
    nFile$ = Text1.Text     '--> enter a new filename into the textbox _
                            with a file extension that you want. e.g., seb.doc
    
    If Dir(Path$ & oFile$) = "" Then
        MsgBox Path$ & oFile$ & " was not found.       ", , "File Not Found"
    Else
        'rename the file
        Shell "cmd.exe /c ren " & Path$ & oFile$ & " " & nFile$, vbHide
        'search if the file has been renamed
        If Dir(Path$ & nFile$) <> "" Then
            MsgBox "Renaming failed!           "
        Else
            MsgBox "The file " & oFile$ & " was successfully renamed to " & nFile$
            End
        End If
    End If
    
End Sub

''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
'''If you like this code, just e-mail me at:
'-------------------------------------------
'''[email protected]
'-------------------------------------------
'''Thank You!
''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''


Download this snippet    Add to My Saved Code

File Renaming Comments

No comments have been posted about File Renaming. Why not be the first to post a comment about File Renaming.

Post your comment

Subject:
Message:
0/1000 characters