?
Solved

Copying just files in directories with the archive attrribute set

Posted on 2003-03-07
8
Medium Priority
?
263 Views
Last Modified: 2010-04-04
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:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20330170.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


0
Comment
Question by:dvanlaar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 8090383
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
0
 

Expert Comment

by:KCBrecks
ID: 8093339
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

0
 

Author Comment

by:dvanlaar
ID: 8101691
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

 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dvanlaar
ID: 8102358
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

 
0
 
LVL 2

Accepted Solution

by:
PeterLarsen earned 300 total points
ID: 8105363
It's better to use FindFirst (or similar function) to find the  files because you may choose to continue - or whatever you want to do - even if a file-copy fails.

>> "But don't know how to just copy those files with thearchive attribute set.."
FindFirst/FindNext only find the files who match the Attr parameter.
0
 

Expert Comment

by:CleanupPing
ID: 9316893
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.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10045287
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question