Como lo puedo hacer en Visual???
Hola como puedo renombrar un fichero.txt para que el resultado sea tres caracteres mas la fecha del sistema?? ejem:GGG151103.txt, os agradeceria un codigo de ejemplo ya que soy novato y no tengo mucha idea.
Saludos.
Saludos.
Pues aquí te pongo un ejemplo, necesitas un textbox
en el que se escribirá el nombre del archivo a renombrar,
y un commandbutton.
Private Sub Command1_Click()
Dim nombreArchivo As String, prefijo As String
Dim ruta As String, extension As String
If (Dir(Text1.Text) <> "") And (Right$(Text1.Text, 1) <> "") Then
Do
prefijo = InputBox("Escribe los tres caracteres iniciales parael nombre del archivo")
Loop While Not (prefijo Like "[a-zA-Z1-9_][a-zA-Z1-9_][a-zA-Z1-9_]")
nombreArchivo = nombreConFecha(prefijo)
ruta = Left$(Text1.Text, InStrRev(Text1.Text, ""))
extension = Right$(Text1.Text, Len(Text1.Text) - InStrRev(Text1.Text, "."))
Name Text1.Text As (ruta & nombreArchivo & "." & extension)
MsgBox ruta & nombreArchivo & extension
Else
MsgBox "Error: " & Text1.Text & " no es un archivo."
End If
End Sub
Private Function nombreConFecha(ByVal prefijo As String) As String
Dim fecha As Date
fecha = Date
nombreConFecha = prefijo & Format(Day(fecha), "00") & Format(Month(fecha), "00") & Format((Year(fecha) Mod 10), "00")
End Function
en el que se escribirá el nombre del archivo a renombrar,
y un commandbutton.
Private Sub Command1_Click()
Dim nombreArchivo As String, prefijo As String
Dim ruta As String, extension As String
If (Dir(Text1.Text) <> "") And (Right$(Text1.Text, 1) <> "") Then
Do
prefijo = InputBox("Escribe los tres caracteres iniciales parael nombre del archivo")
Loop While Not (prefijo Like "[a-zA-Z1-9_][a-zA-Z1-9_][a-zA-Z1-9_]")
nombreArchivo = nombreConFecha(prefijo)
ruta = Left$(Text1.Text, InStrRev(Text1.Text, ""))
extension = Right$(Text1.Text, Len(Text1.Text) - InStrRev(Text1.Text, "."))
Name Text1.Text As (ruta & nombreArchivo & "." & extension)
MsgBox ruta & nombreArchivo & extension
Else
MsgBox "Error: " & Text1.Text & " no es un archivo."
End If
End Sub
Private Function nombreConFecha(ByVal prefijo As String) As String
Dim fecha As Date
fecha = Date
nombreConFecha = prefijo & Format(Day(fecha), "00") & Format(Month(fecha), "00") & Format((Year(fecha) Mod 10), "00")
End Function