@@ -196,51 +196,42 @@ public boolean create(){
196196 public boolean delete (){
197197 return Directory .delete ();
198198 }
199-
200-
199+
200+
201201 //**************************************************************************
202202 //** Copy To
203203 //**************************************************************************
204- /** Used to copy a directory to another directory */
205-
204+ /** Used to copy a directory to another directory. Returns a list of any
205+ * files that failed to copy.
206+ */
206207 public String [] copyTo (Directory Destination , boolean Overwrite ){
207-
208- //Set Local Variables
208+
209209 int source = toString ().length ();
210210 String destination = Destination .toString ();
211- java .util .Vector vec = new java .util .Vector ();
211+
212+ //Create new folder
213+ if (!Destination .exists ()) Destination .create ();
212214
213- //Create Directories
214- Directory [] Directories = getSubDirectories (true );
215- for (int i =0 ; i <Directories .length ; i ++){
216- new Directory (destination + Directories [i ].toString ().substring (source )).create ();
215+ //Create subdirectories
216+ for (Directory dir : getSubDirectories (true )){
217+ new Directory (destination + dir .toString ().substring (source )).create ();
217218 }
218219
219- //Create Files
220- File [] Files = getFiles ( true );
221- for (int i = 0 ; i < Files . length ; i ++ ){
222- String FilePath = Files [ i ] .toString ();
220+ //Copy files
221+ java . util . ArrayList < String > failures = new java . util . ArrayList < String >( );
222+ for (File file : getFiles ( true ) ){
223+ String FilePath = file .toString ();
223224 File out = new File (destination + FilePath .substring (source ));
224225
225- boolean CopiedFile = Files [i ].copyTo (out ,Overwrite );
226-
227- if (CopiedFile ==false ){
228- vec .add (FilePath );
229- //System.out.println(FilePath);
230- }
226+ boolean result = file .copyTo (out ,Overwrite );
227+ if (result ==false ) failures .add (FilePath );
231228 }
232229
233- //Create Array
234- Object [] arr = vec .toArray ();
235- String [] ret = new String [arr .length ];
236- for (int i =0 ; i <ret .length ; i ++){
237- ret [i ] = (String ) arr [i ];
238- }
239-
240- return ret ;
230+ //Return list of failed copies
231+ return failures .toArray (new String [failures .size ()]);
241232 }
242-
243-
233+
234+
244235 //**************************************************************************
245236 //** Move To
246237 //**************************************************************************
@@ -1456,9 +1447,18 @@ else if (obj instanceof java.io.File){
14561447 return false ;
14571448 }
14581449 }
1459-
1460-
1461-
1450+
1451+
1452+ //**************************************************************************
1453+ //** clone
1454+ //**************************************************************************
1455+ /** Creates a copy of this object. */
1456+
1457+ public Directory clone (){
1458+ return new Directory (this .toString ());
1459+ }
1460+
1461+
14621462 //**************************************************************************
14631463 //** getEvents
14641464 //**************************************************************************
0 commit comments