⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copy folder test.htm

📁 sourcecode for folder to folder copy in delphi sorce
💻 HTM
字号:
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">

<head>
<!--[if gte mso 9]><xml><mso:CustomDocumentProperties>
<mso:Approval_x0020_Level msdt:dt="string"></mso:Approval_x0020_Level>
<mso:Categories msdt:dt="string">Utilities;Delphi Techniques</mso:Categories><mso:Assigned_x0020_To msdt:dt="string"></mso:Assigned_x0020_To></mso:CustomDocumentProperties></xml>
<![endif]-->
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Copy Folder Test</title>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<!--mstheme--><link rel="stylesheet" type="text/css" href="../_themes/kidsplainbanner2/kids1110.css"><meta name="Microsoft Theme" content="kidsplainbanner2 1110, default">
<meta name="Microsoft Border" content="tlb">
</head>

<body><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>
<p align="center">
<img border="0" src="../images/ChildDelphi.gif" align="left" vspace="20" width="146" height="113"><font size="6"><strong><img src="_derived/CopyFolder.htm_cmp_kidsplainbanner2110_bnr.gif" width="600" height="60" border="0" alt="Copy Folder Test"></strong></font></p>
<h4 align="center"><br clear="left">
[<a href="../../default.html">Home</a>]&nbsp;&nbsp; [<a href="../index.htm">Projects</a>]&nbsp;&nbsp;&nbsp; 
[<a href="../Delphi_Techniques/index.htm">Delphi Techniques</a>]&nbsp;&nbsp; [<a href="../Math_Topics/index.htm">Math 
Topics</a>]&nbsp;&nbsp; [<a href="../Library/Default.htm">Library</a>]&nbsp;&nbsp; 
[<a href="index.htm">Utilities</a>]</h4>

</td></tr><!--msnavigation--></table><!--msnavigation--><table dir="ltr" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td valign="top" width="1%">
<p>&nbsp;</p>
<div align="left">
	<table cellPadding="5" width="25%" border="0">
		<tr>
			<td width="150">
			<p align="left">
			<img height="10" src="../_borders/bd14710_.gif" width="187" border="0"></p>
			<p align="left"><b>Available Now</b></p>
			<ul>
				<li>
				<p align="left"><b>
				<a href="../Indices/ProgramIndex.htm" target="_blank">All 
				Programs</a></b>
				<ul style="margin-left: 8px">
					<li><a href="../Indices/projectsIndex.htm">Puzzles &amp; 
					Projects</a></li>
					<li><a href="../Indices/Delphi_TechniquesIndex.htm">Delphi 
					Techniques</a></li>
					<li><a href="../Indices/math_topicsIndex.htm">Math Topics</a></li>
					<li><a href="../Indices/UtilitiesIndex.htm">Utilities</a></li>
					<li><a href="../Indices/LibraryIndex.htm">Library Units</a></li>
				</ul>
				</li>
			</ul>
			<p style="MARGIN-TOP: 0px; MARGIN-LEFT: 0px">
			<img height="10" src="../_borders/bd14710_.gif" width="187" border="0"></p>
			<p align="left"><font size="4">Contact</font></p>
			<p><font color="#0000ff" size="2"><a href="../../Feedback.htm">
			Feedback</a>:</font><font face="Arial" color="#000000">&nbsp; </font>
			<font face="Arial" color="#000000" size="2">Send an e-mail with your 
			comments about this program (or anything else).</font></p>
			<p><img height="10" src="../_borders/bd14710_.gif" width="200" border="0"></p>
			<p>
			<!--
//<form method="GET" target="_blank" action="http://www.google.com/search">
// <p style="margin-bottom: 0"><img border="0" src="http://www.google.com/logos/Google_Safe.gif" width="115" height="45"></p>
// <p style="margin-top: 0; margin-bottom: 0"><input type="text" name="q" size="25"> </p>
// <p style="margin-top: 6"><input type="submit" value="Search" name="sa"></p>
// <input type="hidden" name="safe" value="vss"><input type="hidden" name="vss" value="1">
//</form>
--></p>
			<p>
			<!-- Search Google --><a name="Search"></a>
			<left></p>
			<form action="http://www.google.com/custom" method="get">
				<table cellSpacing="0" bgColor="#ffffdd" border="1" width="188">
					<tr vAlign="top">
						<td width="201">
						<a href="http://www.google.com/search?safe=vss">
						<img height="53" alt="Google" src="http://www.google.com/logos/Google_Safe.gif" width="128" align="middle" border="0"></a></td>
					</tr>
					<tr>
						<td width="201">
						<input maxLength="222" size="27" name="q">&nbsp;
						<input type="submit" value="Google Search" name="sa">
						<input type="hidden" value="BGC:ffffdd;AH:center;GL:1;S:http://www.delphiforfun.org;AWFID:87962d146996e3f8;" name="cof">
						<font face="arial,sans-serif" size="-1">
						<input type="hidden" value="delphiforfun.org" name="domains">
						<p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
						<input type="radio" value name="sitesearch"> Search WWW</p>
						<p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
						<input type="radio" CHECKED value="delphiforfun.org" name="sitesearch"> 
						Search delphiforfun.org</p>
						</font>
						<p>&nbsp;</td>
					</tr>
				</table>
			</form>
			<p>
			<!-- Search Google --></p>
			<p><img height="10" src="../_borders/bd14710_.gif" width="200" border="0"></left></td>
		</tr>
	</table>
</div>
<p>&nbsp;</p>

</td><td valign="top" width="24"></td><!--msnavigation--><td valign="top"><table border="0" cellpadding="0" width="100%" cellspacing="0">
  <tr>
    <td width="73%" valign="top">
	<h3 align="left">Problem Description</h3>
    
    <p><font color="#000000">Required: A program to copy all of the files 
	matching a file mask to a different folder.&nbsp; </font></p>
	<h3>Background &amp; Techniques</h3>
	<p>I recently had need for a procedure to copy all files in a CD folder&nbsp; to a new folder on a hard disk drive 
	and reset the &quot;ReadOnly&quot; attributes.&nbsp;&nbsp; .&nbsp; </p>
	<p>This program was written to test the&nbsp;resulting new&nbsp; &quot;CopyFolder&quot; function, but it 
	seems that the program has enough features to perhaps serve as a useful utility for 
	non-programmers..<br>
	<br>
	Usage is straight-forward: Select an input folder and an output folder.&nbsp; 
	The output folder may be existing or a new one.&nbsp; Other 
	options include: </p>
	<ul>
		<li>Set a file mask to control which files get selected.&nbsp; A 
		separate &quot;file masks&quot; page defines masking string options and provides a 
		few examples. </li>
		<li>Set the scope of the operations&nbsp; - files in the input folder&nbsp;only or input folder plus all files in folders contained within the input 
		folder.</li>
		<li>Whether to retain or reset the&nbsp; &quot;readonly&quot; attribute on the 
		copied files.</li>
		<li>How to handle duplicate files, i.e. files already existing in the 
		target folder.&nbsp; options are<ul>
			<li>Ignore the file, do not copy.</li>
			<li>Copy the file, replacing the existing file in the the target 
			folder.</li>
			<li>Copy the file only if the source file is newer than the target.</li>
			<li>Ask the user whether to overwrite the existing target file.</li>
		</ul>
		</li>
	</ul>
	<p>Click the &quot;Copy&quot; button to complete the operation.&nbsp; A list of files copied and the 
	total count will be displayed when the operation has been completed.<br>
	<br>
	You may interrupt the operation by clicking the &quot;Stop&quot; button but the copies 
	of files already processed will remain in the output folder.&nbsp;
	If you select &quot;Ask&quot; option for the Duplicate Files radio group, a reply of 
	&quot;Cancel&quot; when asked will also stop the operation.<br>
&nbsp;</p>
	<p><font color="#000000">Non-programmers are welcome to read on, but may 
    want to <a href="#Download">skip to the bottom of this page</a> to download 
    executable version of the program.</font></p>
	<h4><b><font color="#000000">Notes for Programmers</font></b></h4>
	<p>The program calls the &quot;<b>CopyFolder</b>&quot; function contained in unit <b>
	UCopyFolder</b>.pas to do most of the work.&nbsp;&nbsp; <b>CopyFolder</b> 
	copies files matching a given mask from one folder to another. Parameters 
	are;</p>
	<ul>
		<li><b>FromFolder</b>: The path to the folder containing the files to be 
		copied</li>
		<li><b>ToFolder</b>: The path to the folder to receiver the files</li>
		<li><b>Mask</b>: A file mask to control which files are selected ('*.*' = 
		All files)</li>
		<li><b>DupFileOpts</b>: Four numeric options are available when the file already 
		exists:<ul>
			<li>0 ==&gt; skip the file</li>
			<li>1 ==&gt; always copy the file</li>
			<li>2 ==&gt; copy the file if it is newer than the existing copy</li>
			<li>3 ==&gt; ask the user what action to take</li>
		</ul>
		</li>
		<li><b>CopySubFolders</b>: Files in subfolders of the specified <b>
		FromPath</b> folder will also be copied if this parameter is true.</li>
		<li><b>ResetReadOnly</b>: If true, input files marked as &quot;Readonly&quot; will 
		have that attribute removed in the target location.</li>
		<li><b>FileExit</b>: The address of optional method (function of object) 
		specifying a user function to be called before each file is copied.&nbsp; 
		If the callback procedure is specified, it receives 4 parameters:<ul>
			<li><b>Inpath</b>: Path to the input file.</li>
			<li><b>OutputPath</b>: Path where the file will be copied.</li>
			<li><b>Filename</b>: Name of the file to be copied.</li>
			<li><b>Cancopy</b>: Boolean parameter with a default value of true. Set &quot;<b>Cancopy</b>&quot; 
			to false to skip copying this file.</li>
		</ul>
		</li>
	</ul>
	<blockquote>
		<p><b>FileExit</b> should&nbsp; return a result value of true if copying is to continue,&nbsp; and 
		false to abort the copy procedure without copying further files.</p>
	</blockquote>
	<p>&nbsp;</p>
	<p><b>CopyFolder </b>uses a few techniques worth describing for future 
	reference</p>
	<ul>
		<li><font color="#000000"><b>Recursive search through a folder and 
		subfolders </b>is a technique we have used before but filtering files 
		with a file mask makes the procedure a little more complicated.&nbsp; 
		The <b>FindFirst</b> function can filter returned records based on a 
		specified file mask, but since we will likely be recursively calling <b>
		CopyFolder</b>&nbsp; with subdirectories of the input directory, <b>
		FindFirst</b> must search all file names (with a file name mask of 
		&quot;*.*&quot;)</font></li>
		<li><font color="#000000"><b>File mask matching</b> - <b>FindFirst</b> 
		and successive <b>FindNext</b> calls&nbsp; retrieve file information in 
		a <b>TSearchrec</b> for each call including the file name, date, 
		attributes .&nbsp; The Name field is passed to the
		<b>MatchesMask</b> function along with the user specified mask.&nbsp; I 
		could find no user oriented description of mask strings, so I added a tab 
		sheet to the program with the mask&nbsp; fields described and a few examples.&nbsp;&nbsp; </font></li>
		<li><font color="#000000"><b>Overloading a function or procedure with an 
		optional method call </b>- I decided to provide an optional callback 
		function passed as a parameter to CopyFolder.&nbsp; The callback 
		function is called for each file to be copied,&nbsp; passing the 
		parameters described above.&nbsp; The typical way to make a parameter 
		optional is to provide an overloaded version without the optional 
		parameter&nbsp; and from there call the &quot;real&quot; version with a default 
		value for the missing parameter.&nbsp; (Delphi recognizes the keyword &quot;<b>overload</b>&quot; 
		in the procedure definition and will accept multiple definitions with 
		the same name so long as the parameter lists are different.)&nbsp; The tricky part here is that we 
		cannot pass a &quot;Nil&quot; (no address) value for the callback function because 
		the function is defined as a method type&nbsp; function &quot;of object&quot; 
		meaning that it is a method of an object.&nbsp;&nbsp; Method type 
		functions are passed as a pair of pointers, a pointer to the function 
		code and a a pointer to the class instance to which it belongs.&nbsp;&nbsp;&nbsp; 
		I got around the problem by defining a <b>DummyFileExit</b> function 
		within a <b>TDummyClass</b> definition.&nbsp; And an instance if <b>
		TDummyClass </b>name<b>d DummyClass</b>.&nbsp; This <b>DummyfFileExit</b> 
		may now be passed as the default <b>FileExit</b> for cases where the 
		user chose not to provide one.&nbsp; <b>CopyFile</b> checks and ignores 
		any reference to <b>DummyFileExit</b>, so it is not necessary to 
		actually create the <b>DummyClass</b> instance.&nbsp;&nbsp; Whew!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</font></li>
		<li><font color="#000000"><b>Changing file attributes</b> - I only way i 
		could find to reset the <b>ReadOnly</b> attribute was to copy the (using 
		the Windows <b>CopyFile</b> funtion) and then use the <b>SetFileAttr</b> 
		function to reset the attribute if in was set in the input. </font></li>
	</ul>
    
    <h3><a name="Download"></a>Running/Exploring the Program&nbsp;</h3>
      <ul>
        <li>
        <font color="#000000"><a href="../Download/CopyFolderTestSource.zip">Download source</a></font><a href="../Download/MonitorOffSource.zip">
		</a>
        </li>
        <li>
        <font color="#000000"><a href="../Download/CopyFolderTest.zip">Download&nbsp; executable</a></font><a href="../Download/MonitorOff.zip">
		</a>
        </li>
      </ul>
    
    <h3>Suggestions for Further Explorations</h3>
    
    <p><font color="#000000">I&nbsp;Is there a more direct way to make a method 
	pointer an optional parameter in a function call?</font></p>
    <p>&nbsp; </p>
    <div align="left">
      
      <table border="0" cellpadding="2" width="100%">
        <tr>
          <td width="50%"><b><font size="2">
          Original Date: October 30 2006</font></b></td>
          <td width="50%">
          <p align="right"><b><font size="2">Modified:
          <!--webbot bot="Timestamp" s-type="EDITED" s-format="%B %d, %Y" startspan -->February 01, 2007<!--webbot bot="Timestamp" i-checksum="41395" endspan --> </font></b></td>
        </tr>
      </table>
      
    </div>
    </td>
  </tr>
</table>

<p>&nbsp; </p>


<!--msnavigation--></td></tr><!--msnavigation--></table><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>
<hr>
<h5 align="center"><font color="#0000FF">&nbsp; [<a href="../../Feedback.htm">Feedback</a>]&nbsp;&nbsp; 
[<a href="../../newsletter.htm">Newsletters (subscribe/view</a>)] [</font><font color="#330033"><a href="../../about_me.htm">About 
me</a></font><font color="#0000FF">]</font></h5>
<h5 align="center"><font color="#000080">Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -