Board index » delphi » File Modification

File Modification

Hi all,

I'm trying to work out how to see if a file has changed.
I've got two different locations but each location containing the same
filename. Once the filename on one location has been changed the program has
to give me the newest file of the two of them.
Problem is, if I copy the new file over the old file, the date value of the
overwritten file becomes newer than the other file so the program thinks
that file is now newer than the other.

Get it?

Who can help me out.

I'm trying to find some sort of way to find a date attr. of a file that
doesn't change with copying.

Thanks in advance !

 

Re:File Modification


On Sat, 7 Jun 2003 10:04:13 +0200, "Sander Martens"

Quote
<sandermart...@msn.com> wrote:
>Hi all,

>I'm trying to work out how to see if a file has changed.
>I've got two different locations but each location containing the same
>filename. Once the filename on one location has been changed the program has
>to give me the newest file of the two of them.
>Problem is, if I copy the new file over the old file, the date value of the
>overwritten file becomes newer than the other file so the program thinks
>that file is now newer than the other.

>Get it?

No !
- copying a file should not change its date
- a copy routine should use FileGetDate and FileSetDate

- things get a bit more complicated on OSes where the last access date
is stored - but in this case it should not be relevant to you

How _exactly_ is the file being 'copied' ?

Is FTP involved in this ?

Re:File Modification


Hi J,

I wrote down the code I've written. After the copy, the date of the copied
file is changed to the date and time of copying.
I hope this makes it a bit better to understand? I'm running this in Windows
XP by the way.

Kind Regards,

procedure TForm1.Button1Click(Sender: TObject);

var Originalfilename : string;
    Newfilename : string;
    Newfile : TFileStream;
    Originalfile : TFileStream;

begin
Originalfilename :=
ExtractFilePath(FileListBox2.FileName)+ExtractFileName(FileListBox2.FileName
);
Originalfile := TFileStream.Create(Originalfilename, fmOpenRead or
fmShareDenyNone);
Newfilename := ExtractFilePath(FileListBox1.FileName)+'test2.doc';
Newfile := TFileStream.Create(Newfilename, fmCreate or fmShareDenyRead);
Newfile.CopyFrom (Originalfile, Originalfile.Size);
end;

"J French" <Bounce_It_je...@iss.u-net.com_.bin> schreef in bericht
news:3ee19f61.8679770@news.btclick.com...

Quote
> On Sat, 7 Jun 2003 10:04:13 +0200, "Sander Martens"
> <sandermart...@msn.com> wrote:

> >Hi all,

> >I'm trying to work out how to see if a file has changed.
> >I've got two different locations but each location containing the same
> >filename. Once the filename on one location has been changed the program
has
> >to give me the newest file of the two of them.
> >Problem is, if I copy the new file over the old file, the date value of
the
> >overwritten file becomes newer than the other file so the program thinks
> >that file is now newer than the other.

> >Get it?
> No !
> - copying a file should not change its date
> - a copy routine should use FileGetDate and FileSetDate

> - things get a bit more complicated on OSes where the last access date
> is stored - but in this case it should not be relevant to you

> How _exactly_ is the file being 'copied' ?

> Is FTP involved in this ?

Re:File Modification


Response below :-

On Sat, 7 Jun 2003 11:13:56 +0200, "Sander Martens"

Quote
<sandermart...@msn.com> wrote:
>Hi J,

>I wrote down the code I've written. After the copy, the date of the copied
>file is changed to the date and time of copying.
>I hope this makes it a bit better to understand? I'm running this in Windows
>XP by the way.

>Kind Regards,

>procedure TForm1.Button1Click(Sender: TObject);

>var Originalfilename : string;
>    Newfilename : string;
>    Newfile : TFileStream;
>    Originalfile : TFileStream;

>begin
>Originalfilename :=
>ExtractFilePath(FileListBox2.FileName)+ExtractFileName(FileListBox2.FileName
>);
>Originalfile := TFileStream.Create(Originalfilename, fmOpenRead or
>fmShareDenyNone);
>Newfilename := ExtractFilePath(FileListBox1.FileName)+'test2.doc';
>Newfile := TFileStream.Create(Newfilename, fmCreate or fmShareDenyRead);
>Newfile.CopyFrom (Originalfile, Originalfile.Size);
>end;

Yes, I see what you are doing
- the odd 'Free' would not go amiss

- Personally I would use THandleStreams
- But a TFileStream has a Handle Property

    Var
        Dte :Integer;
    ...
    Dte := FileGetDate( OriginalFile.Handle );
    FileSetDate( NewFile.Handle, Dte );

That will copy across the date of the original file
- if it is the last thing you do before :-
    NewFile.Free;

Re:File Modification


the file dates won't change if you use the API methods of file copy..
  the ShFileOperation works well for this.
 if you do a read/write in your own app then of course its copy to
create the current dates..
  one thing to note also that when copying from CD's using the API
methods the CD attributes tend to get copied with it making it a nuisance.
Quote
J French wrote:
> On Sat, 7 Jun 2003 10:04:13 +0200, "Sander Martens"
> <sandermart...@msn.com> wrote:

> >Hi all,

> >I'm trying to work out how to see if a file has changed.
> >I've got two different locations but each location containing the same
> >filename. Once the filename on one location has been changed the program has
> >to give me the newest file of the two of them.
> >Problem is, if I copy the new file over the old file, the date value of the
> >overwritten file becomes newer than the other file so the program thinks
> >that file is now newer than the other.

> >Get it?
> No !
> - copying a file should not change its date
> - a copy routine should use FileGetDate and FileSetDate

> - things get a bit more complicated on OSes where the last access date
> is stored - but in this case it should not be relevant to you

> How _exactly_ is the file being 'copied' ?

> Is FTP involved in this ?

Other Threads