2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FIoDirectory.h
20 * @brief This is the header file for the %Directory class.
22 * This header file contains the declarations of the %Directory class.
25 #ifndef _FIO_DIRECTORY_H_
26 #define _FIO_DIRECTORY_H_
28 #include <FBaseObject.h>
29 #include <FBaseTypes.h>
30 #include <FBaseString.h>
31 #include <FBaseDateTime.h>
32 #include <FBaseColArrayList.h>
33 #include <FIoDirEntry.h>
34 #include <FIoDirEnumerator.h>
36 namespace Tizen { namespace Io
41 * @brief This class provides methods to operate on directories.
45 * @final This class is not intended for extension.
47 * The %Directory class provides methods to operate on directories.
49 * For more information on the class features,
50 * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
52 * @see Tizen::Io::DirEntry
53 * @see Tizen::Io::File
55 * The following example demonstrates how to use the %Directory class.
62 using namespace Tizen::Base;
63 using namespace Tizen::Io;
64 using namespace Tizen::App;
71 DirEnumerator* pDirEnum;
74 dirName = App::GetInstance()->GetAppDataPath() + L"test";
75 modifyName = App::GetInstance()->GetAppDataPath() + L"test2";
77 //------------------------------------------------
78 // Directory entry traversal example
79 //------------------------------------------------
80 pDir = new Directory; // Allocates the %Directory instance
83 r = pDir->Construct(dirName);
89 // Reads all the directory entries
90 pDirEnum = pDir->ReadN();
96 // Loops through all the directory entries
97 while (pDirEnum->MoveNext() == E_SUCCESS)
99 DirEntry entry = pDirEnum->GetCurrentDirEntry();
104 // Releases the %Directory instance.
105 // The opened directory is closed automatically when the destructor of the %Directory class is invoked.
109 //------------------------------------------------
110 // Renames the directory example
111 //------------------------------------------------
112 r = Directory::Rename(dirName, modifyName);
117 AppLog("Succeeded!");
132 class _OSP_EXPORT_ Directory
133 : public Tizen::Base::Object
138 * The object is not fully constructed after this constructor is called. 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: @n
170 * - The length of the specified path is @c 0 or exceeds system limitations. @n
171 * - The specified path contains prohibited character(s). @n
172 * - The specified path is invalid.
173 * @exception E_ILLEGAL_ACCESS 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: @n
177 * - An unexpected device failure has occurred as the media ejected suddenly. @n
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 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: @n
193 * - An unexpected device failure has occurred as the media ejected suddenly. @n
194 * - %File corruption is detected.
195 * @remarks The returned enumeration objects should be released by the caller. @n
196 * The specific error code can be accessed using the GetLastResult() method.
198 DirEnumerator* ReadN(void);
201 * Creates a new directory.
204 * @brief <i> [Compatibility] </i>
208 * @compatibility This method has compatibility issues with OSP compatible applications. @n
209 * For more information, see @ref CompIoPathPage "here".
212 * @return An error code
213 * @param[in] dirPath The path at which the directory is created
214 * @param[in] createParentDirectories Set to @c true if the non-existing parent directories are created automatically
215 * up to the destination, @n
216 * else @c false if an absent parent directory causes an exception
217 * @exception E_SUCCESS The method is successful.
218 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
219 * - The length of the specified path is @c 0 or exceeds system limitations. @n
220 * - The specified path is invalid.
221 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
222 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
223 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
224 * @exception E_STORAGE_FULL The disk space is full.
225 * @exception E_IO Either of the following conditions has occurred: @n
226 * - An unexpected device failure has occurred as the media ejected suddenly. @n
227 * - %File corruption is detected.
229 static result Create(const Tizen::Base::String& dirPath, bool createParentDirectories = false);
232 * Deletes the directory specified by the path. @n
233 * When @c recursive is set to be @c true, it removes all the subdirectories and their contents. @n
234 * When @c false, this method removes the directory only if it is empty.
237 * @brief <i> [Compatibility] </i>
241 * @compatibility This method has compatibility issues with OSP compatible applications. @n
242 * For more information, see @ref CompIoPathPage "here".
245 * @return An error code
246 * @param[in] dirPath The path of the directory to remove
247 * @param[in] recursive Set to @c true to remove the sub-directories recursively, @n
249 * @exception E_SUCCESS The method is successful.
250 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
251 * - The length of the specified path is @c 0 or exceeds
252 * system limitations. @n
253 * - The specified @c dirPath is not directory path.
254 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
255 * @exception E_FILE_NOT_FOUND The specified @c dirPath cannot be found.
256 * @exception E_FILE_ALREADY_EXIST The specified directory already exists.
257 * @exception E_MAX_EXCEEDED The number of opened directories has exceeded the maximum limit.
258 * @exception E_IO Either of the following conditions has occurred: @n
259 * - An unexpected device failure has occurred as the media ejected suddenly. @n
260 * - %File corruption is detected.
262 static result Remove(const Tizen::Base::String& dirPath, bool recursive = false);
265 * Renames the specified directory to the specified name. @n
266 * This method is static. @n
267 * This method does not create parent directories automatically. For example, @b "/CurrentDir" cannot be moved to
268 * @b "/NewDir/SubDir" if @b "/NewDir" does not already exist. An E_FILE_NOT_FOUND exception is thrown.
271 * @brief <i> [Compatibility] </i>
275 * @compatibility This method has compatibility issues with OSP compatible applications. @n
276 * For more information, see @ref CompIoPathPage "here".
279 * @return An error code
280 * @param[in] orgDirPath The original directory path
281 * @param[in] newDirPath The new directory path
282 * @exception E_SUCCESS The method is successful.
283 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
284 * - The length of the specified path is @c 0 or exceeds system limitations. @n
285 * - The specified path is invalid.
286 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
287 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
288 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
289 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
290 * @exception E_STORAGE_FULL The disk space is full.
291 * @exception E_IO Either of the following conditions has occurred: @n
292 * - An unexpected device failure has occurred as the media ejected suddenly. @n
293 * - %File corruption is detected.
295 static result Rename(const Tizen::Base::String& orgDirPath, const Tizen::Base::String& newDirPath);
299 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
303 Directory(const Directory& rhs);
306 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
310 Directory& operator =(const Directory& rhs);
312 class _DirectoryImpl* __pDirectoryImpl;
314 friend class _DirectoryImpl;
320 #endif // _FIO_DIRECTORY_H_