ObjFW
OFFileManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFDictionary.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
23 #ifdef OF_HAVE_FILES
24 # if defined(OF_HAVE_CHMOD) && !defined(OF_AMIGAOS)
25 # define OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
26 # endif
27 # if defined(OF_HAVE_CHOWN) && !defined(OF_AMIGAOS)
28 # define OF_FILE_MANAGER_SUPPORTS_OWNER
29 # endif
30 # if (defined(OF_HAVE_LINK) && !defined(OF_AMIGAOS)) || defined(OF_WINDOWS)
31 # define OF_FILE_MANAGER_SUPPORTS_LINKS
32 # endif
33 # if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || defined(OF_WINDOWS)
34 # define OF_FILE_MANAGER_SUPPORTS_SYMLINKS
35 # endif
36 #endif
37 
38 @class OFArray OF_GENERIC(ObjectType);
39 @class OFConstantString;
40 @class OFDate;
41 @class OFString;
42 @class OFURL;
43 
65 
82 
87 typedef OFDictionary OF_GENERIC(of_file_attribute_key_t, id)
89 
94 typedef OFMutableDictionary OF_GENERIC(of_file_attribute_key_t, id)
96 
97 #ifdef __cplusplus
98 extern "C" {
99 #endif
107 
117 
125 
133 
141 
149 
157 
165 
173 
181 
189 
196 extern const of_file_attribute_key_t
198 
203 
208 
213 
217 extern const of_file_type_t of_file_type_fifo;
218 
223 
228 
233 #ifdef __cplusplus
234 }
235 #endif
236 
243 #ifndef OF_FILE_MANAGER_M
244 OF_SUBCLASSING_RESTRICTED
245 #endif
247 #ifdef OF_HAVE_CLASS_PROPERTIES
248 @property (class, readonly, nonatomic) OFFileManager *defaultManager;
249 #endif
250 
251 #ifdef OF_HAVE_FILES
255 @property (readonly, nonatomic) OFString *currentDirectoryPath;
256 
260 @property (readonly, nonatomic) OFURL *currentDirectoryURL;
261 #endif
262 
267 
268 #ifdef OF_HAVE_FILES
276 - (of_file_attributes_t)attributesOfItemAtPath: (OFString *)path;
277 #endif
278 
286 - (of_file_attributes_t)attributesOfItemAtURL: (OFURL *)URL;
287 
288 #ifdef OF_HAVE_FILES
297 - (void)setAttributes: (of_file_attributes_t)attributes
298  ofItemAtPath: (OFString *)path;
299 #endif
300 
309 - (void)setAttributes: (of_file_attributes_t)attributes
310  ofItemAtURL: (OFURL *)URL;
311 
312 #ifdef OF_HAVE_FILES
319 - (bool)fileExistsAtPath: (OFString *)path;
320 #endif
321 
328 - (bool)fileExistsAtURL: (OFURL *)URL;
329 
330 #ifdef OF_HAVE_FILES
337 - (bool)directoryExistsAtPath: (OFString *)path;
338 #endif
339 
346 - (bool)directoryExistsAtURL: (OFURL *)URL;
347 
348 #ifdef OF_HAVE_FILES
354 - (void)createDirectoryAtPath: (OFString *)path;
355 
362 - (void)createDirectoryAtPath: (OFString *)path
363  createParents: (bool)createParents;
364 #endif
365 
371 - (void)createDirectoryAtURL: (OFURL *)URL;
372 
379 - (void)createDirectoryAtURL: (OFURL *)URL createParents: (bool)createParents;
380 
381 #ifdef OF_HAVE_FILES
390 - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path;
391 #endif
392 
401 - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtURL: (OFURL *)URL;
402 
403 #ifdef OF_HAVE_FILES
409 - (void)changeCurrentDirectoryPath: (OFString *)path;
410 
416 - (void)changeCurrentDirectoryURL: (OFURL *)URL;
417 
431 - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination;
432 #endif
433 
447 - (void)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
448 
449 #ifdef OF_HAVE_FILES
463 - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination;
464 #endif
465 
479 - (void)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
480 
481 #ifdef OF_HAVE_FILES
489 - (void)removeItemAtPath: (OFString *)path;
490 #endif
491 
499 - (void)removeItemAtURL: (OFURL *)URL;
500 
501 #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS
513 - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination;
514 #endif
515 
527 - (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
528 
529 #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
544 - (void)createSymbolicLinkAtPath: (OFString *)path
545  withDestinationPath: (OFString *)target;
546 #endif
547 
562 - (void)createSymbolicLinkAtURL: (OFURL *)URL
563  withDestinationPath: (OFString *)target;
564 @end
565 
566 @interface OFDictionary (FileAttributes)
572 @property (readonly, nonatomic) unsigned long long fileSize;
573 
579 @property (readonly, nonatomic) of_file_type_t fileType;
580 
587 @property (readonly, nonatomic) unsigned long filePOSIXPermissions;
588 
594 @property (readonly, nonatomic) unsigned long filePOSIXUID;
595 
601 @property (readonly, nonatomic) unsigned long filePOSIXGID;
602 
608 @property (readonly, nonatomic) OFString *fileOwner;
609 
615 @property (readonly, nonatomic) OFString *fileGroup;
616 
623 @property (readonly, nonatomic) OFDate *fileLastAccessDate;
624 
631 @property (readonly, nonatomic) OFDate *fileModificationDate;
632 
639 @property (readonly, nonatomic) OFDate *fileStatusChangeDate;
640 
646 @property (readonly, nonatomic) OFDate *fileCreationDate;
647 
654 @property (readonly, nonatomic) OFString *fileSymbolicLinkDestination;
655 @end
656 
657 OF_ASSUME_NONNULL_END
OFConstantString * of_file_attribute_key_t
A key for a file attribute in the file attributes dictionary.
Definition: OFFileManager.h:42
const of_file_type_t of_file_type_socket
A socket.
Definition: OFFileManager.m:106
const of_file_attribute_key_t of_file_attribute_key_group
The group of the file as an OFString.
Definition: OFFileManager.m:86
const of_file_type_t of_file_type_regular
A regular file.
Definition: OFFileManager.m:99
const of_file_attribute_key_t of_file_attribute_key_last_access_date
The last access date of the file as an OFDate.
Definition: OFFileManager.m:88
const of_file_attribute_key_t of_file_attribute_key_posix_permissions
The POSIX permissions of the file as an OFNumber.
Definition: OFFileManager.m:78
const of_file_attribute_key_t of_file_attribute_key_type
The type of the file.
Definition: OFFileManager.m:76
const of_file_attribute_key_t of_file_attribute_key_posix_gid
The POSIX GID of the file as an OFNumber.
Definition: OFFileManager.m:82
const of_file_attribute_key_t of_file_attribute_key_modification_date
The last modification date of the file as an OFDate.
Definition: OFFileManager.m:90
const of_file_type_t of_file_type_character_special
A character special file.
Definition: OFFileManager.m:103
const of_file_attribute_key_t of_file_attribute_key_status_change_date
The last status change date of the file as an OFDate.
Definition: OFFileManager.m:92
const of_file_type_t of_file_type_block_special
A block special file.
Definition: OFFileManager.m:105
const of_file_attribute_key_t of_file_attribute_key_symbolic_link_destination
The destination of a symbolic link as an OFString.
Definition: OFFileManager.m:96
const of_file_type_t of_file_type_fifo
A FIFO.
Definition: OFFileManager.m:102
const of_file_attribute_key_t of_file_attribute_key_size
The size of the file as an OFNumber.
Definition: OFFileManager.m:74
OFMutableDictionary * of_mutable_file_attributes_t
A mutable dictionary mapping keys of type of_file_attribute_key_t to their attribute values.
Definition: OFFileManager.h:95
OFConstantString * of_file_type_t
The type of a file.
Definition: OFFileManager.h:81
const of_file_type_t of_file_type_directory
A directory.
Definition: OFFileManager.m:100
const of_file_attribute_key_t of_file_attribute_key_creation_date
The creation date of the file as an OFDate.
Definition: OFFileManager.m:94
OFDictionary * of_file_attributes_t
A dictionary mapping keys of type of_file_attribute_key_t to their attribute values.
Definition: OFFileManager.h:88
const of_file_attribute_key_t of_file_attribute_key_owner
The owner of the file as an OFString.
Definition: OFFileManager.m:84
const of_file_type_t of_file_type_symbolic_link
A symbolic link.
Definition: OFFileManager.m:101
const of_file_attribute_key_t of_file_attribute_key_posix_uid
The POSIX UID of the file as an OFNumber.
Definition: OFFileManager.m:80
An abstract class for storing objects in an array.
Definition: OFArray.h:92
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A class for storing, accessing and comparing dates.
Definition: OFDate.h:36
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:58
A class which provides management for files, e.g. reading contents of directories,...
Definition: OFFileManager.h:247
OFFileManager * defaultManager()
Returns the default file manager.
Definition: OFFileManager.m:155
OFURL * currentDirectoryURL
The URL of the current working directory.
Definition: OFFileManager.h:260
OFString * currentDirectoryPath
The path of the current working directory.
Definition: OFFileManager.h:255
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:44
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class for handling strings.
Definition: OFString.h:132
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:34