Source code: com/flexstor/common/io/xfile/XFileDelete.java
1 /*
2 * XFileDelete.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:39 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.io.xfile;
12
13 /**
14 * XFileDelete has the capability to delete files and directories both local and remote.
15 * Overloaded methods are provided to enable the deletion of a directory, if the file to delete is the
16 * only one in that directory; and to recursively delete directories if a request to delete a directory
17 * is requested.
18 */
19 public class XFileDelete
20 extends XFileAccessorFactory
21 {
22 public XFileDelete()
23 {
24 super( DELETE );
25 }
26
27 /**
28 * Deletes the directory specified. This operation will delete any files and subdirectories within
29 * the directory specified.
30 *
31 * @param sDir - The directory to delete
32 * @param return true if successful, false otherwise
33 */
34 public boolean deleteDirectory( String sDir )
35 {
36 System.out.println( "#### Deleting " + sDir );
37 if ( validateOperation(sDir) )
38 return ((XFileDeleteI)fAccessor).deleteDirectory( sDir );
39 else
40 return false;
41 }
42
43 /**
44 * Deletes the directory specified. If the second argument is false, it will remove the directory
45 * only if it is empty; if true, it will delete the directory and all of its content.
46 *
47 * @param sDir - The directory to delete
48 * @param bDeleteContent - Boolean value to specify whether the directory's content should be
49 * deleted or not.
50 * @return true if successful, false otherwise
51 */
52 public boolean deleteDirectory( String sDir, boolean bDeleteContent )
53 {
54 System.out.println( "#### Deleting " + sDir );
55 if ( validateOperation(sDir) )
56 return ((XFileDeleteI)fAccessor).deleteDirectory( sDir, bDeleteContent );
57 else
58 return false;
59 }
60
61 /**
62 * Deletes the file specified. If the file is the only one left, its directory will also be
63 * removed.
64 *
65 * @param sFile - The file to delete
66 * @return true if successful, false otherwise
67 */
68 public boolean deleteFile( String sFile )
69 {
70 System.out.println( "#### Deleting " + sFile );
71 if ( validateOperation(sFile) )
72 return ((XFileDeleteI)fAccessor).deleteFile( sFile );
73 else
74 return false;
75 }
76
77 /**
78 * Deletes the file specified. If the second argument is true, it will remove the directory if it
79 * is empty; if false, it will not remove the directory even if it is empty.
80 *
81 * @param sFile - The file to delete
82 * @param bRemoveParentIfEmpty - Boolean value to specify whether the parent directory of the file
83 * should be deleted or not.
84 * @return true if successful, false otherwise
85 */
86 public boolean deleteFile( String sFile, boolean bRemoveParentIfEmpty )
87 {
88 System.out.println( "#### Deleting " + sFile );
89 if ( validateOperation(sFile) )
90 return ((XFileDeleteI)fAccessor).deleteFile( sFile, bRemoveParentIfEmpty );
91 else
92 return false;
93 }
94 }