2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIoDirectory.h
19 * @brief This is the header file for the %Directory class.
21 * This header file contains the declarations of the %Directory class.
24 #ifndef _FIO_DIRECTORY_H_
25 #define _FIO_DIRECTORY_H_
27 #include <FBaseObject.h>
28 #include <FBaseTypes.h>
29 #include <FBaseString.h>
30 #include <FBaseDateTime.h>
31 #include <FBaseColArrayList.h>
32 #include <FIoDirEntry.h>
33 #include <FIoDirEnumerator.h>
35 namespace Tizen { namespace Io
40 * @brief This class provides methods for directory operations.
44 * @final This class is not intended for extension.
46 * The %Directory class provides methods for directory operations.
48 * For more information on the class features,
49 * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
51 * @see Tizen::Io::DirEntry
52 * @see Tizen::Io::File
54 * The following example demonstrates how to use the %Directory class.
61 using namespace Tizen::Base;
62 using namespace Tizen::Io;
63 using namespace Tizen::App;
70 DirEnumerator* pDirEnum;
73 dirName = App::GetInstance()->GetAppDataPath() + L"test";
74 modifyName = App::GetInstance()->GetAppDataPath() + L"test2";
76 //------------------------------------------------
77 // Directory entry traversal example
78 //------------------------------------------------
79 pDir = new Directory; // Allocates the %Directory instance
82 r = pDir->Construct(dirName);
88 // Reads all the directory entries
89 pDirEnum = pDir->ReadN();
95 // Loops through all the directory entries
96 while (pDirEnum->MoveNext() == E_SUCCESS)
98 DirEntry entry = pDirEnum->GetCurrentDirEntry();
103 // Releases the %Directory instance.
104 // The opened directory is closed automatically when the destructor of the %Directory class is invoked.
108 //------------------------------------------------
109 // Renames the directory example
110 //------------------------------------------------
111 r = Directory::Rename(dirName, modifyName);
116 AppLog("Succeeded!");
131 class _OSP_EXPORT_ Directory
132 : public Tizen::Base::Object
137 * The object is not fully constructed after this constructor is called. @n
138 * For full construction, the Construct() method must be called right after calling this constructor.
142 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
147 * This destructor overrides Tizen::Base::Object::~Object().
151 virtual ~Directory(void);
154 * Initializes this instance of %Directory with the specified parameter. @n
155 * The Construct() method safely opens an existing directory using the specified directory name.
158 * @brief <i> [Compatibility] </i>
162 * @compatibility This method has compatibility issues with OSP compatible applications. @n
163 * For more information, see @ref CompIoPathPage "here".
166 * @return An error code
167 * @param[in] dirPath The path to the directory to open
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_INVALID_ARG Either of the following conditions has occurred:
170 * - The length of the specified path is @c 0 or exceeds system limitations.
171 * - The specified path contains prohibited character(s).
172 * - The specified path is invalid.
173 * @exception E_ILLEGAL_ACCESS The access is denied due to insufficient permission.
174 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
175 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
176 * @exception E_IO Either of the following conditions has occurred:
177 * - An unexpected device failure has occurred as the media ejected suddenly.
178 * - %File corruption is detected.
180 result Construct(const Tizen::Base::String& dirPath);
183 * Reads all the directory entries from the current directory and then returns a DirEnumerator instance that is used to traverse each directory entry.
187 * @return A pointer to the DirEnumerator object that provides a way to access the collection of a directory entry list, @n
188 * else @c null if an exception occurs
189 * @exception E_SUCCESS The method is successful.
190 * @exception E_ILLEGAL_ACCESS The access is denied due to insufficient permission.
191 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
192 * @exception E_IO Either of the following conditions has occurred:
193 * - An unexpected device failure has occurred as the media ejected suddenly.
194 * - %File corruption is detected.
196 * - The returned enumeration objects should be released by the caller.
197 * - The specific error code can be accessed using the GetLastResult() method.
199 DirEnumerator* ReadN(void);
202 * Creates a new directory.
205 * @brief <i> [Compatibility] </i>
209 * @compatibility This method has compatibility issues with OSP compatible applications. @n
210 * For more information, see @ref CompIoPathPage "here".
213 * @return An error code
214 * @param[in] dirPath The path to create the directory
215 * @param[in] createParentDirectories Set to @c true to create the non-existing parent directories automatically
216 * up to the destination, @n
217 * else @c false to throw an exception in case of absent parent directory
218 * @exception E_SUCCESS The method is successful.
219 * @exception E_INVALID_ARG Either of the following conditions has occurred:
220 * - The length of the specified path is @c 0 or exceeds system limitations.
221 * - The specified path is invalid.
222 * @exception E_ILLEGAL_ACCESS The access is denied due to insufficient permission.
223 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
224 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
225 * @exception E_STORAGE_FULL The disk space is full.
226 * @exception E_IO Either of the following conditions has occurred:
227 * - An unexpected device failure has occurred as the media ejected suddenly.
228 * - %File corruption is detected.
230 static result Create(const Tizen::Base::String& dirPath, bool createParentDirectories = false);
233 * Deletes the directory specified by the path. @n
234 * When @c recursive is set to be @c true, it removes all the subdirectories and their contents. @n
235 * When @c false, this method removes the directory only if it is empty.
238 * @brief <i> [Compatibility] </i>
242 * @compatibility This method has compatibility issues with OSP compatible applications. @n
243 * For more information, see @ref CompIoPathPage "here".
246 * @return An error code
247 * @param[in] dirPath The path of the directory to remove
248 * @param[in] recursive Set to @c true to remove the sub-directories recursively, @n
250 * @exception E_SUCCESS The method is successful.
251 * @exception E_INVALID_ARG Either of the following conditions has occurred:
252 * - The length of the specified path is @c 0 or exceeds
253 * system limitations.
254 * - The specified @c dirPath is not directory path.
255 * @exception E_ILLEGAL_ACCESS The access is denied due to insufficient permission.
256 * @exception E_FILE_NOT_FOUND The specified @c dirPath cannot be found.
257 * @exception E_FILE_ALREADY_EXIST The specified directory already exists.
258 * @exception E_MAX_EXCEEDED The number of opened directories has exceeded the maximum limit.
259 * @exception E_IO Either of the following conditions has occurred:
260 * - An unexpected device failure has occurred as the media ejected suddenly.
261 * - %File corruption is detected.
263 static result Remove(const Tizen::Base::String& dirPath, bool recursive = false);
266 * Renames the specified directory to the specified name. @n
267 * This method is static. @n
268 * This method does not create parent directories automatically. For example, @b "/CurrentDir" cannot be moved to
269 * @b "/NewDir/SubDir" if @b "/NewDir" does not already exist. An E_FILE_NOT_FOUND exception is thrown.
272 * @brief <i> [Compatibility] </i>
276 * @compatibility This method has compatibility issues with OSP compatible applications. @n
277 * For more information, see @ref CompIoPathPage "here".
280 * @return An error code
281 * @param[in] orgDirPath The original directory path
282 * @param[in] newDirPath The new directory path
283 * @exception E_SUCCESS The method is successful.
284 * @exception E_INVALID_ARG Either of the following conditions has occurred:
285 * - The length of the specified path is @c 0 or exceeds system limitations.
286 * - The specified path is invalid.
287 * @exception E_ILLEGAL_ACCESS The access is denied due to insufficient permission.
288 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
289 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
290 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
291 * @exception E_STORAGE_FULL The disk space is full.
292 * @exception E_IO Either of the following conditions has occurred:
293 * - An unexpected device failure has occurred as the media ejected suddenly.
294 * - %File corruption is detected.
296 static result Rename(const Tizen::Base::String& orgDirPath, const Tizen::Base::String& newDirPath);
300 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
304 Directory(const Directory& rhs);
307 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
311 Directory& operator =(const Directory& rhs);
313 class _DirectoryImpl* __pDirectoryImpl;
315 friend class _DirectoryImpl;
321 #endif // _FIO_DIRECTORY_H_