@@ -56,25 +56,45 @@ namespace iText.Commons.Utils {
56
56
public static class FileUtil {
57
57
private static int tempFileCounter = 0 ;
58
58
59
+ /// <summary>
60
+ /// Gets the default windows font directory.
61
+ /// </summary>
62
+ /// <returns>the default windows font directory</returns>
59
63
public static String GetFontsDir ( ) {
60
64
String windir = Environment . GetEnvironmentVariable ( "windir" ) ;
61
65
return windir != null ? Path . Combine ( windir , "fonts" ) : "" ;
62
66
}
63
67
68
+ /// <summary>
69
+ /// Checks whether there is a file at the provided path.
70
+ /// </summary>
71
+ /// <param name="path">the path to the file to be checked on existence</param>
72
+ /// <returns><CODE>true</CODE> if such a file exists, otherwise <CODE>false</CODE></returns>
64
73
public static bool FileExists ( String path ) {
65
74
if ( ! String . IsNullOrEmpty ( path ) ) {
66
75
return new FileInfo ( path ) . Exists ;
67
76
}
68
77
return false ;
69
78
}
70
79
80
+ /// <summary>
81
+ /// Checks whether there is a directory at the provided path.
82
+ /// </summary>
83
+ /// <param name="path">the path to the directory to be checked on existence</param>
84
+ /// <returns>true if such a directory exists, otherwise false</returns>
71
85
public static bool DirectoryExists ( String path ) {
72
86
if ( ! String . IsNullOrEmpty ( path ) ) {
73
87
return new DirectoryInfo ( path ) . Exists ;
74
88
}
75
89
return false ;
76
90
}
77
91
92
+ /// <summary>
93
+ /// Lists all the files located at the provided directory.
94
+ /// </summary>
95
+ /// <param name="path">path to the directory</param>
96
+ /// <param name="recursive">if <CODE>true</CODE>, files from all the subdirectories will be returned</param>
97
+ /// <returns>all the files located at the provided directory</returns>
78
98
public static String [ ] ListFilesInDirectory ( String path , bool recursive ) {
79
99
if ( ! String . IsNullOrEmpty ( path ) ) {
80
100
DirectoryInfo dir = new DirectoryInfo ( path ) ;
@@ -92,10 +112,23 @@ public static String[] ListFilesInDirectory(String path, bool recursive) {
92
112
return null ;
93
113
}
94
114
115
+ /// <summary>
116
+ /// Lists all the files located at the provided directory, which are accepted by the provided filter.
117
+ /// </summary>
118
+ /// <param name="path">path to the directory</param>
119
+ /// <param name="filter">filter to accept files to be listed</param>
120
+ /// <returns>all the files located at the provided directory, which are accepted by the provided filter</returns>
95
121
public static FileInfo [ ] ListFilesInDirectoryByFilter ( String path , IFileFilter filter ) {
96
122
return ListFilesInDirectoryByFilter ( path , false , filter ) ;
97
123
}
98
124
125
+ /// <summary>
126
+ /// Lists all the files located at the provided directory, which are accepted by the provided filter.
127
+ /// </summary>
128
+ /// <param name="path">path to the directory</param>
129
+ /// <param name="recursive">if <CODE>true</CODE>, files from all the subdirectories will be returned</param>
130
+ /// <param name="filter">filter to accept files to be listed</param>
131
+ /// <returns>all the files located at the provided directory, which are accepted by the provided filter</returns>
99
132
public static FileInfo [ ] ListFilesInDirectoryByFilter ( String path , bool recursive , IFileFilter filter ) {
100
133
if ( ! String . IsNullOrEmpty ( path ) ) {
101
134
DirectoryInfo dir = new DirectoryInfo ( path ) ;
@@ -123,6 +156,12 @@ public static Stream GetBufferedOutputStream(String filename) {
123
156
return new FileStream ( filename , FileMode . Create ) ;
124
157
}
125
158
159
+ /// <summary>
160
+ /// Creates a temporary file at the provided path.
161
+ /// </summary>
162
+ /// <param name="path">path to the temporary file to be created. If it is a directory,
163
+ /// then the temporary file will be created at this directory</param>
164
+ /// <returns>the created temporary file</returns>
126
165
public static FileInfo CreateTempFile ( String path ) {
127
166
if ( DirectoryExists ( path ) ) {
128
167
return new FileInfo ( path + Path . DirectorySeparatorChar + "pdf_" + Interlocked . Increment ( ref tempFileCounter ) ) ;
@@ -148,6 +187,10 @@ public static Stream WrapWithBufferedOutputStream(Stream outputStream)
148
187
return outputStream ;
149
188
}
150
189
190
+ /// <summary>
191
+ /// Creates a directory at the provided path.
192
+ /// </summary>
193
+ /// <param name="outPath">path to the directory to be created</param>
151
194
public static void CreateDirectories ( String outPath ) {
152
195
Directory . CreateDirectory ( outPath ) ;
153
196
}
0 commit comments