ObjFW
OFFileManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2023 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)) || defined(DOXYGEN)
25 # define OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
26 # endif
27 # if (defined(OF_HAVE_CHOWN) && !defined(OF_AMIGAOS)) || defined(DOXYGEN)
28 # define OF_FILE_MANAGER_SUPPORTS_OWNER
29 # endif
30 # if (defined(OF_HAVE_LINK) && !defined(OF_AMIGAOS)) || defined(OF_WINDOWS) || \
31  defined(DOXYGEN)
32 # define OF_FILE_MANAGER_SUPPORTS_LINKS
33 # endif
34 # if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || \
35  defined(OF_WINDOWS) || defined(DOXYGEN)
36 # define OF_FILE_MANAGER_SUPPORTS_SYMLINKS
37 # endif
38 # if defined(OF_LINUX) || defined(OF_MACOS) || defined(DOXYGEN)
39 # define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
40 # endif
41 #endif
42 
43 @class OFArray OF_GENERIC(ObjectType);
44 @class OFConstantString;
45 @class OFDate;
46 @class OFIRI;
47 @class OFString;
48 
71 
89 
95 
100 typedef OFMutableDictionary OF_GENERIC(OFFileAttributeKey, id)
102 
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106 
112 extern const OFFileAttributeKey OFFileSize;
113 
122 extern const OFFileAttributeKey OFFileType;
123 
131 
139 
147 
155 
163 
171 
179 
187 
195 
203 
212 
217 
222 
227 
232 
237 
242 
247 
256 #ifdef __cplusplus
257 }
258 #endif
259 
266 #ifndef OF_FILE_MANAGER_M
267 OF_SUBCLASSING_RESTRICTED
268 #endif
270 #ifdef OF_HAVE_CLASS_PROPERTIES
271 @property (class, readonly, nonatomic) OFFileManager *defaultManager;
272 #endif
273 
274 #ifdef OF_HAVE_FILES
275 
280 @property (readonly, nonatomic) OFString *currentDirectoryPath;
281 
287 @property (readonly, nonatomic) OFIRI *currentDirectoryIRI;
288 #endif
289 
294 
295 #ifdef OF_HAVE_FILES
296 
305 - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path;
306 #endif
307 
319 - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI;
320 
321 #ifdef OF_HAVE_FILES
322 
335 - (void)setAttributes: (OFFileAttributes)attributes
336  ofItemAtPath: (OFString *)path;
337 #endif
338 
354 - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI;
355 
356 #ifdef OF_HAVE_FILES
357 
363 - (bool)fileExistsAtPath: (OFString *)path;
364 #endif
365 
374 - (bool)fileExistsAtIRI: (OFIRI *)IRI;
375 
376 #ifdef OF_HAVE_FILES
377 
383 - (bool)directoryExistsAtPath: (OFString *)path;
384 #endif
385 
394 - (bool)directoryExistsAtIRI: (OFIRI *)IRI;
395 
396 #ifdef OF_HAVE_FILES
397 
403 - (void)createDirectoryAtPath: (OFString *)path;
404 
413 - (void)createDirectoryAtPath: (OFString *)path
414  createParents: (bool)createParents;
415 #endif
416 
425 - (void)createDirectoryAtIRI: (OFIRI *)IRI;
426 
437 - (void)createDirectoryAtIRI: (OFIRI *)IRI createParents: (bool)createParents;
438 
439 #ifdef OF_HAVE_FILES
440 
450 - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path;
451 #endif
452 
466 - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI;
467 
468 #ifdef OF_HAVE_FILES
469 
478 - (OFArray OF_GENERIC(OFString *) *)subpathsOfDirectoryAtPath: (OFString *)path;
479 
487 - (void)changeCurrentDirectoryPath: (OFString *)path;
488 
496 - (void)changeCurrentDirectoryIRI: (OFIRI *)IRI;
497 
514 - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination;
515 #endif
516 
535 - (void)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
536 
537 #ifdef OF_HAVE_FILES
538 
559 - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination;
560 #endif
561 
585 - (void)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
586 
587 #ifdef OF_HAVE_FILES
588 
596 - (void)removeItemAtPath: (OFString *)path;
597 #endif
598 
609 - (void)removeItemAtIRI: (OFIRI *)IRI;
610 
611 #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS
612 
626 - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination;
627 #endif
628 
645 - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
646 
647 #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
648 
665 - (void)createSymbolicLinkAtPath: (OFString *)path
666  withDestinationPath: (OFString *)target;
667 #endif
668 
686 - (void)createSymbolicLinkAtIRI: (OFIRI *)IRI
687  withDestinationPath: (OFString *)target;
688 
689 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
690 
703 - (OFData *)extendedAttributeDataForName: (OFString *)name
704  ofItemAtPath: (OFString *)path;
705 #endif
706 
722 - (OFData *)extendedAttributeDataForName: (OFString *)name
723  ofItemAtIRI: (OFIRI *)IRI;
724 
725 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
726 
740 - (void)setExtendedAttributeData: (OFData *)data
741  forName: (OFString *)name
742  ofItemAtPath: (OFString *)path;
743 #endif
744 
761 - (void)setExtendedAttributeData: (OFData *)data
762  forName: (OFString *)name
763  ofItemAtIRI: (OFIRI *)IRI;
764 
765 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
766 
779 - (void)removeExtendedAttributeForName: (OFString *)name
780  ofItemAtPath: (OFString *)path;
781 #endif
782 
798 - (void)removeExtendedAttributeForName: (OFString *)name
799  ofItemAtIRI: (OFIRI *)IRI;
800 @end
801 
802 @interface OFDictionary (FileAttributes)
808 @property (readonly, nonatomic) unsigned long long fileSize;
809 
815 @property (readonly, nonatomic) OFFileAttributeType fileType;
816 
822 @property (readonly, nonatomic) unsigned long filePOSIXPermissions;
823 
829 @property (readonly, nonatomic) unsigned long fileOwnerAccountID;
830 
836 @property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID;
837 
843 @property (readonly, nonatomic) OFString *fileOwnerAccountName;
844 
850 @property (readonly, nonatomic) OFString *fileGroupOwnerAccountName;
851 
857 @property (readonly, nonatomic) OFDate *fileLastAccessDate;
858 
864 @property (readonly, nonatomic) OFDate *fileModificationDate;
865 
871 @property (readonly, nonatomic) OFDate *fileStatusChangeDate;
872 
878 @property (readonly, nonatomic) OFDate *fileCreationDate;
879 
885 @property (readonly, nonatomic) OFString *fileSymbolicLinkDestination;
886 
892 @property (readonly, nonatomic)
894 @end
895 
896 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:103
const OFFileAttributeKey OFFileModificationDate
The last modification date of the file as an OFDate.
const OFFileAttributeType OFFileTypeSocket
A socket.
OFConstantString * OFFileAttributeKey
A key for a file attribute in the file attributes dictionary.
Definition: OFFileManager.h:47
const OFFileAttributeKey OFFileLastAccessDate
The last access date of the file as an OFDate.
const OFFileAttributeType OFFileTypeSymbolicLink
A symbolic link.
const OFFileAttributeType OFFileTypeFIFO
A FIFO.
A class for storing, accessing and comparing dates.
Definition: OFDate.h:29
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:37
A class which provides management for files, e.g. reading contents of directories, deleting files, renaming files, etc.
Definition: OFFileManager.h:269
The root class for all other classes inside ObjFW.
Definition: OFObject.h:686
OFIRI * currentDirectoryIRI
The IRI of the current working directory.
Definition: OFFileManager.h:287
const OFFileAttributeKey OFFileExtendedAttributesNames
The names of the extended attributes as an OFArray of OFString.
const OFFileAttributeKey OFFileOwnerAccountID
The account ID of the owner of the file as an OFNumber.
const OFFileAttributeKey OFFileSymbolicLinkDestination
The destination of a symbolic link as an OFString.
const OFFileAttributeKey OFFileSize
The size of the file as an OFNumber.
OFDictionary * OFFileAttributes
A dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition: OFFileManager.h:94
const OFFileAttributeKey OFFileGroupOwnerAccountID
The account ID of the group owner of the file as an OFNumber.
A class for handling strings.
Definition: OFString.h:134
const OFFileAttributeKey OFFileStatusChangeDate
The last status change date of the file as an OFDate.
const OFFileAttributeKey OFFileType
The type of the file.
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:78
const OFFileAttributeKey OFFileOwnerAccountName
The account name of the owner of the file as an OFString.
OFFileManager * defaultManager()
Returns the default file manager.
Definition: OFFileManager.m:132
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:42
const OFFileAttributeType OFFileTypeDirectory
A directory.
const OFFileAttributeType OFFileTypeBlockSpecial
A block special file.
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:35
OFArray * fileExtendedAttributesNames
The OFFileExtendedAttributesNames key from the dictionary.
Definition: OFFileManager.h:893
const OFFileAttributeType OFFileTypeCharacterSpecial
A character special file.
const OFFileAttributeKey OFFilePOSIXPermissions
The POSIX permissions of the file as an OFNumber.
A class for storing arbitrary data in an array.
Definition: OFData.h:41
const OFFileAttributeKey OFFileCreationDate
The creation date of the file as an OFDate.
const OFFileAttributeType OFFileTypeRegular
A regular file.
const OFFileAttributeType OFFileTypeUnknown
An unknown file type.
OFString * currentDirectoryPath
The path of the current working directory.
Definition: OFFileManager.h:280
const OFFileAttributeKey OFFileGroupOwnerAccountName
The account name of the group owner of the file as an OFString.
OFMutableDictionary * OFMutableFileAttributes
A mutable dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition: OFFileManager.h:101
OFConstantString * OFFileAttributeType
The type of a file.
Definition: OFFileManager.h:88