Fordraiders
asked on
Rename a file and add the System Date and Time
vb.net 2003
I need to rename a file and ad the system date and system time?
Is this possible?
Dim Filename as "MyWork.xls"
RenameFile("C:\Dm2007\Outb ox\" & FileName, "Completed_" & FileName)
Thanks
fordraiders
I need to rename a file and ad the system date and system time?
Is this possible?
Dim Filename as "MyWork.xls"
RenameFile("C:\Dm2007\Outb
Thanks
fordraiders
fordraiders,
although you should probably add some error checking like this:
Dim Path As String = "C:\temp\"
Dim Filename As String = "Test.doc"
If System.IO.File.Exists(Path & Filename) Then
If Not System.IO.File.Exists(Path & "Completed_" & Filename) Then
System.IO.File.Move(Path & Filename, Path & "Completed_" & Filename)
Else
Messagebox.show("Can't rename file as destination file already exists.")
End If
Else
Messagebox.show("Can't find target file.")
End If
although you should probably add some error checking like this:
Dim Path As String = "C:\temp\"
Dim Filename As String = "Test.doc"
If System.IO.File.Exists(Path
If Not System.IO.File.Exists(Path
System.IO.File.Move(Path & Filename, Path & "Completed_" & Filename)
Else
Messagebox.show("Can't rename file as destination file already exists.")
End If
Else
Messagebox.show("Can't find target file.")
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi fordraiders;
This should do what you want.
Dim Filename As String = "MyWork.xls"
Dim NewFilename As String = Path.GetFileNameWithoutExt ension(Fil ename)
NewFilename &= "-" & Now.ToString("MMddyyyy-hhm mss")
NewFilename &= Path.GetExtension(Filename )
File.Move("C:\Dm2007\Outbo x\" & Filename, "C:\Dm2007\Outbox\" & NewFilename")
Fernando
This should do what you want.
Dim Filename As String = "MyWork.xls"
Dim NewFilename As String = Path.GetFileNameWithoutExt
NewFilename &= "-" & Now.ToString("MMddyyyy-hhm
NewFilename &= Path.GetExtension(Filename
File.Move("C:\Dm2007\Outbo
Fernando
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
vbturbo,
VB.net
Does not like this line
NewName = "C:\Dm2007\Outbox\" & FileName, "Completed_" & FileName & DateAndTime
VB.net
Does not like this line
NewName = "C:\Dm2007\Outbox\" & FileName, "Completed_" & FileName & DateAndTime
That's because DateAndTime will probably have the "\" character in the date part - which the file system won't like :)
This is why I used the Format() in my last post.
This is why I used the Format() in my last post.
ASKER
Hillwaa,
vb.does not like the "format" syntax in the code.
vb.does not like the "format" syntax in the code.
What error are you getting?
Format(Now, "yyyyMMddhhmm") works fine for me?
Format(Now, "yyyyMMddhhmm") works fine for me?
ASKER
its just underlined
syntax is not correct....
I got this to work...
But When I try to add date and time
It does not like it....
Rename("C:\Dm2007\Outbox\" & FileName, "C:\Dm2007\Outbox\" & "Completed_" & FileName)
Thanks
fordraiders
syntax is not correct....
I got this to work...
But When I try to add date and time
It does not like it....
Rename("C:\Dm2007\Outbox\"
Thanks
fordraiders
ASKER
Got this to take at least the date
Rename("C:\Dm2007\Outbox\" & FileName, "C:\Dm2007\Outbox\" & "Completed_" & Replace(FormatDateTime(Now (), 2), "/", "") & FileName)
Rename("C:\Dm2007\Outbox\"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this:
Dim Path As String = "C:\Dm2007\Outbox\"
Dim Filename As String = "MyWork.xls"
System.IO.File.Move(Path & Filename, Path & "Completed_" & Filename)
Cheers,
Hillwaaa