I'm copying a file:
File.Copy("File1","File2")
When copied, the file will have it's file date and time preserved. How can I make the newely copied file take on the date and time at that moment of copy?
Thanks
Printable View
I'm copying a file:
File.Copy("File1","File2")
When copied, the file will have it's file date and time preserved. How can I make the newely copied file take on the date and time at that moment of copy?
Thanks
System.IO.File has members which include SetCreationTime, SetLastAccessTime and SetLastWriteTime.
Haven't tried it :) but it looks promising.
Try this:
Code:using System;
using System.IO;
class MyFile
{
static void FileCopy(string source, string destination, bool overwrite, bool changeTimestamp)
{
System.IO.File.Copy(source, destination, overwrite);
if(changeTimestamp)
{
File.SetCreationTime(destination, DateTime.Now);
}
}
static void Main()
{
MyFile.FileCopy(@"d:\dummy.txt", @"d:\dummyCopy.txt", true, true);
}
}
The above is C++ ..................................
anyway, almost identical, the SetCreationTime didn't work as the date was the same.
The only way I've found to do it now is like this, which works:
Works OK but a bit 'long winded' if you ask me.Code:Dim fi As New FileInfo(MyFile)
Dim aDate As DateTime = (Date.Now)
fi.CreationTime = aDate
fi.LastAccessTime = aDate
fi.LastWriteTime = aDate
Thanks
Actually, it's C#.....................
;)
lol, that's what I meant.... it was late.