i have a Label1.Text that displays a randomly produced number. is there a way to rename a file using Label1.Text as the file name
Let's assume your file is originally named "oldfile.txt" and is on the root of "C:\"
-----
Dim oldFileName As String = "C:\Oldfile.txt"
Dim newFileName As String = Label1.Text
My. Computer. FileSystem. RenameFile (oldFileName, newFileName)
(Of course, you shouldn't put spaces after the dots in that last line. I did, in order to keep Yahoo from truncating the long string, so you could see the whole thing.)
You need to "move" the file
Dim fi As New FileInfo("myImage.gif")
fi.MoveTo("myImage2.gif")
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
Verified answer
Let's assume your file is originally named "oldfile.txt" and is on the root of "C:\"
-----
Dim oldFileName As String = "C:\Oldfile.txt"
Dim newFileName As String = Label1.Text
My. Computer. FileSystem. RenameFile (oldFileName, newFileName)
-----
(Of course, you shouldn't put spaces after the dots in that last line. I did, in order to keep Yahoo from truncating the long string, so you could see the whole thing.)
You need to "move" the file
Dim fi As New FileInfo("myImage.gif")
fi.MoveTo("myImage2.gif")