Link to home
Start Free TrialLog in
Avatar of dvanlaar
dvanlaar

asked on

Copying just files in directories with the archive attrribute set

I used to back up new files on my harddisk drives to my network drive using the dos command:

copy c:\ed\*.* n:\edbackup\ /s /m /i /d:10/10/2002

that is: copy everything in c:\ed\ directory to n:\edbackup\ ; inlcude subdiretories;, if a new or modified file [archive attribute will have been set]then copy this file over, but switch off the archive attribute in the original ; assume if destination does not exist that destination is a directory; copy everything created or modified since date of last big backup.

This no longer works on my windows 2000 system, and i'm trying to produce a more flexible system in Delphi.  I have an efficient file copy procedure thanks to expertsXexchange based on the ShellAPI:
https://www.experts-exchange.com/questions/20330170/copying-multiple-files-from-a-directory-to-another-directory.html

But don't know how to just copy those files with thearchive attribute set (and to turn it off of the files I've copied). Is there an easy (and efficient) way to do this,or do I have to do it the long way (open each relevant file, copy line by line, close, etc)??

help much appreciated,

Daz


Avatar of PeterLarsen
PeterLarsen

Hi Daz,

Hope this will help :

procedure TForm1.Button1Click(Sender: TObject);
var
 SR: TSearchRec;
begin
 if FindFirst(IncludeTrailingBackslash(ExtractFilePath(Application.ExeName))+'*.*', $00000020, SR) = 0 then
 begin
  repeat

   {Do your copy stuff here with CopyFile or save the
    names in a list for later use with SHFileOperation}

  until FindNext(SR) <> 0;
  FindClose(SR);
 end; //end if
end;


Peter
If you want to alter the attribitres for a file then the FileSetAttr() function is available in the SysUtils unit. Look in the Help system for File Attributes

Unit

Sysutils

Category

file management routines

function FileSetAttr(const FileName: string; Attr: Integer): Integer;

Description

FileSetAttr sets the file attributes of the file given by FileName to the value given by Attr. The value of Attr is formed by combining the appropriate file attribute constants, as in the following:

FileSetAttr('MyFile.sys', faReadOnly or faSysFile);

FileSetAttr returns zero if the function was successful. Otherwise the return value is a Windows error code.

Note:     See TSearchRec for a description of the file attribute constants.

This is a straight copy of the Delphi Help file.

Keith

Avatar of dvanlaar

ASKER

Thanks so far,

Finding and setting the attributes on the individual files and then copying them individually is not the problem. I would like to only copy particular files within a *very* large directory structure using a quick and efficient copy procedure such as ShellAPI FO_COPY or similar.  

Is there anyway of checking the attributes of the files as they are being copied over,or only letting the ShellAPI copy procedure 'see' files with a particular attribute?

I know this can be done as it appears to be implemented in the Dos copy, xcopy or xcopy32 commands.

Daz

 
Thanks so far,

Finding and setting the attributes on the individual files and then copying them individually is not the problem. I would like to only copy particular files within a *very* large directory structure using a quick and efficient copy procedure such as ShellAPI FO_COPY or similar.  

Is there anyway of checking the attributes of the files as they are being copied over,or only letting the ShellAPI copy procedure 'see' files with a particular attribute?

I know this can be done as it appears to be implemented in the Dos copy, xcopy or xcopy32 commands.

Daz

 
ASKER CERTIFIED SOLUTION
Avatar of PeterLarsen
PeterLarsen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dvanlaar:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
https://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: PeterLarsen

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer