Copying files

  • Thread starter Thread starter Lars Black
  • Start date Start date
L

Lars Black

I need to copy some file from a SD Card to a folder on my PPC. Using
File.Copy doesn't seem to preserve the timestamp of the file, so how do I do
that?

An existing app/sample that can handle it would also be of great interest.
Basically, I have a text file with "From / To" filenames and need to copy
each one of these.

Cheers,
Lars
 
Probably, you'll want to read the source file time and then use it to set
the file time of the destination file after the copy is done. You know,
GetCreationTime(), then SetCreationTime(), etc.

Paul T.
 
Sorry about that; those methods aren't in the CF. Here's the declaration
for SetFileTime in the Win32 API.

[DllImport("coredll.dll", SetLastError=true)]

private static extern bool SetFileTime( int hfile,

ref long creationTime,

ref long writeTime,

ref long accessTime );



You'll have to get the declaration for CreateFile() to open the file, and
CloseHandle() to close it. They are both in OpenNETCF, for your
convenience.



Are you sure that File.Copy() isn't setting the time correctly for you? On
the Windows CE.NET emulator, it *does* set the file time of the destination
to the source time.



Paul T.
 
And, on a real device, File.Copy() *does* copy the file time, too.

Paul T.

Paul G. Tobey said:
Sorry about that; those methods aren't in the CF. Here's the declaration
for SetFileTime in the Win32 API.

[DllImport("coredll.dll", SetLastError=true)]

private static extern bool SetFileTime( int hfile,

ref long creationTime,

ref long writeTime,

ref long accessTime );



You'll have to get the declaration for CreateFile() to open the file, and
CloseHandle() to close it. They are both in OpenNETCF, for your
convenience.



Are you sure that File.Copy() isn't setting the time correctly for you? On
the Windows CE.NET emulator, it *does* set the file time of the destination
to the source time.



Paul T.



Paul G. Tobey said:
Probably, you'll want to read the source file time and then use it to set
the file time of the destination file after the copy is done. You know,
GetCreationTime(), then SetCreationTime(), etc.

Paul T.
do
 
And, on a real device, File.Copy() *does* copy the file time, too.

Thank you Paul, very useful!

Cheers,
Lars
 
Back
Top