|
-
Mar 25th, 2003, 01:41 PM
#1
Thread Starter
Member
File Date & Time on Copy
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
-
Mar 25th, 2003, 04:06 PM
#2
Frenzied Member
System.IO.File has members which include SetCreationTime, SetLastAccessTime and SetLastWriteTime.
Haven't tried it but it looks promising.
-
Mar 25th, 2003, 06:48 PM
#3
PowerPoster
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);
}
}
-
Mar 25th, 2003, 07:51 PM
#4
Thread Starter
Member
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:
Code:
Dim fi As New FileInfo(MyFile)
Dim aDate As DateTime = (Date.Now)
fi.CreationTime = aDate
fi.LastAccessTime = aDate
fi.LastWriteTime = aDate
Works OK but a bit 'long winded' if you ask me.
Thanks
-
Mar 25th, 2003, 08:54 PM
#5
PowerPoster
Actually, it's C#.....................
-
Mar 26th, 2003, 06:27 AM
#6
Thread Starter
Member
lol, that's what I meant.... it was late.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|