ObjFW
OFFileManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #import "OFDictionary.h"
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
27 #ifdef OF_HAVE_FILES
28 # if (defined(OF_HAVE_CHMOD) && !defined(OF_NINTENDO_DS)) || defined(DOXYGEN)
29 # define OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
30 # endif
31 # if defined(OF_HAVE_CHOWN) || defined(DOXYGEN)
32 # define OF_FILE_MANAGER_SUPPORTS_OWNER
33 # endif
34 # if (defined(OF_HAVE_LINK) && !defined(OF_AMIGAOS) && \
35  !defined(OF_NINTENDO_DS)) || defined(OF_WINDOWS) || defined(DOXYGEN)
36 # define OF_FILE_MANAGER_SUPPORTS_LINKS
37 # endif
38 # if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS) && \
39  !defined(OF_NINTENDO_DS)) || defined(OF_WINDOWS) || defined(DOXYGEN)
40 # define OF_FILE_MANAGER_SUPPORTS_SYMLINKS
41 # endif
42 # if defined(OF_LINUX) || defined(OF_MACOS) || defined(OF_FREEBSD) || \
43  defined(OF_NETBSD) || defined(OF_HAIKU) || defined(OF_SOLARIS) || \
44  defined(DOXYGEN)
45 # define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
46 # endif
47 #endif
48 
49 @class OFArray OF_GENERIC(ObjectType);
50 @class OFConstantString;
51 @class OFDate;
52 @class OFIRI;
53 @class OFNumber;
54 @class OFString;
55 
59 typedef enum {
71  OFFileAmigaPure = 0x0020,
75  OFFileAmigaHold = 0x0080,
93 
97 typedef enum {
111 
137 
155 
161 
166 typedef OFMutableDictionary OF_GENERIC(OFFileAttributeKey, id)
168 
169 #ifdef __cplusplus
170 extern "C" {
171 #endif
178 extern const OFFileAttributeKey OFFileSize;
179 
188 extern const OFFileAttributeKey OFFileType;
189 
197 
205 
213 
221 
229 
237 
245 
253 
261 
269 
278 
285 
290 
297 
302 
307 
312 
317 
322 
327 
332 
341 #ifdef __cplusplus
342 }
343 #endif
344 
351 #ifndef OF_FILE_MANAGER_M
352 OF_SUBCLASSING_RESTRICTED
353 #endif
355 #ifdef OF_HAVE_CLASS_PROPERTIES
356 @property (class, readonly, nonatomic) OFFileManager *defaultManager;
357 #endif
358 
359 #ifdef OF_HAVE_FILES
365 @property (readonly, nonatomic) OFString *currentDirectoryPath;
366 
372 @property (readonly, nonatomic) OFIRI *currentDirectoryIRI;
373 #endif
374 
379 
380 #ifdef OF_HAVE_FILES
390 - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path;
391 #endif
392 
404 - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI;
405 
406 #ifdef OF_HAVE_FILES
420 - (void)setAttributes: (OFFileAttributes)attributes
421  ofItemAtPath: (OFString *)path;
422 #endif
423 
439 - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI;
440 
441 #ifdef OF_HAVE_FILES
448 - (bool)fileExistsAtPath: (OFString *)path;
449 #endif
450 
459 - (bool)fileExistsAtIRI: (OFIRI *)IRI;
460 
461 #ifdef OF_HAVE_FILES
468 - (bool)directoryExistsAtPath: (OFString *)path;
469 #endif
470 
479 - (bool)directoryExistsAtIRI: (OFIRI *)IRI;
480 
481 #ifdef OF_HAVE_FILES
488 - (void)createDirectoryAtPath: (OFString *)path;
489 
498 - (void)createDirectoryAtPath: (OFString *)path
499  createParents: (bool)createParents;
500 #endif
501 
510 - (void)createDirectoryAtIRI: (OFIRI *)IRI;
511 
522 - (void)createDirectoryAtIRI: (OFIRI *)IRI createParents: (bool)createParents;
523 
524 #ifdef OF_HAVE_FILES
535 - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path;
536 #endif
537 
551 - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI;
552 
553 #ifdef OF_HAVE_FILES
563 - (OFArray OF_GENERIC(OFString *) *)subpathsOfDirectoryAtPath: (OFString *)path;
564 
572 - (void)changeCurrentDirectoryPath: (OFString *)path;
573 
581 - (void)changeCurrentDirectoryIRI: (OFIRI *)IRI;
582 
599 - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination;
600 #endif
601 
620 - (void)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
621 
622 #ifdef OF_HAVE_FILES
644 - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination;
645 #endif
646 
670 - (void)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
671 
672 #ifdef OF_HAVE_FILES
681 - (void)removeItemAtPath: (OFString *)path;
682 #endif
683 
694 - (void)removeItemAtIRI: (OFIRI *)IRI;
695 
696 #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS
711 - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination;
712 #endif
713 
730 - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
731 
732 #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
750 - (void)createSymbolicLinkAtPath: (OFString *)path
751  withDestinationPath: (OFString *)target;
752 #endif
753 
771 - (void)createSymbolicLinkAtIRI: (OFIRI *)IRI
772  withDestinationPath: (OFString *)target;
773 
774 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
790 - (OFData *)extendedAttributeDataForName: (OFString *)name
791  ofItemAtPath: (OFString *)path;
792 
812 - (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
813  andType: (id _Nullable *_Nullable)type
814  forName: (OFString *)name
815  ofItemAtPath: (OFString *)path;
816 #endif
817 
835 - (OFData *)extendedAttributeDataForName: (OFString *)name
836  ofItemAtIRI: (OFIRI *)IRI;
837 
859 - (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
860  andType: (id _Nullable *_Nullable)type
861  forName: (OFString *)name
862  ofItemAtIRI: (OFIRI *)IRI;
863 
864 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
879 - (void)setExtendedAttributeData: (OFData *)data
880  forName: (OFString *)name
881  ofItemAtPath: (OFString *)path;
882 
902 - (void)setExtendedAttributeData: (OFData *)data
903  andType: (nullable id)type
904  forName: (OFString *)name
905  ofItemAtPath: (OFString *)path;
906 #endif
907 
924 - (void)setExtendedAttributeData: (OFData *)data
925  forName: (OFString *)name
926  ofItemAtIRI: (OFIRI *)IRI;
927 
949 - (void)setExtendedAttributeData: (OFData *)data
950  andType: (nullable id)type
951  forName: (OFString *)name
952  ofItemAtIRI: (OFIRI *)IRI;
953 
954 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
968 - (void)removeExtendedAttributeForName: (OFString *)name
969  ofItemAtPath: (OFString *)path;
970 #endif
971 
987 - (void)removeExtendedAttributeForName: (OFString *)name
988  ofItemAtIRI: (OFIRI *)IRI;
989 @end
990 
991 @interface OFDictionary (FileAttributes)
997 @property (readonly, nonatomic) unsigned long long fileSize;
998 
1004 @property (readonly, nonatomic) OFFileAttributeType fileType;
1005 
1011 @property (readonly, nonatomic) unsigned long filePOSIXPermissions;
1012 
1018 @property (readonly, nonatomic) unsigned long fileOwnerAccountID;
1019 
1025 @property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID;
1026 
1032 @property (readonly, nonatomic) OFString *fileOwnerAccountName;
1033 
1039 @property (readonly, nonatomic) OFString *fileGroupOwnerAccountName;
1040 
1046 @property (readonly, nonatomic) OFDate *fileLastAccessDate;
1047 
1053 @property (readonly, nonatomic) OFDate *fileModificationDate;
1054 
1060 @property (readonly, nonatomic) OFDate *fileStatusChangeDate;
1061 
1067 @property (readonly, nonatomic) OFDate *fileCreationDate;
1068 
1074 @property (readonly, nonatomic) OFString *fileSymbolicLinkDestination;
1075 
1081 @property (readonly, nonatomic)
1082  OFArray OF_GENERIC(OFString *) *fileExtendedAttributesNames;
1083 
1089 @property (readonly, nonatomic) OFFileAmigaProtectionMask fileAmigaProtection;
1090 
1096 @property (readonly, nonatomic) OFString *fileAmigaComment;
1097 
1103 @property (readonly, nonatomic) OFFileMSDOSAttributesMask fileMSDOSAttributes;
1104 @end
1105 
1106 OF_ASSUME_NONNULL_END
const OFFileAttributeType OFFileTypeFIFO
A FIFO.
const OFFileAttributeKey OFFileCreationDate
The creation date of the file as an OFDate.
const OFFileAttributeKey OFFileOwnerAccountName
The account name of the owner of the file as an OFString.
const OFFileAttributeKey OFFileExtendedAttributesNames
The names of the extended attributes as an OFArray of OFString.
OFFileMSDOSAttributesMask
MS-DOS attributes. This is a bit mask and the values are ORed.
Definition: OFFileManager.h:97
@ OFFileMSDOSAttributeSystem
The file is a system file.
Definition: OFFileManager.h:103
@ OFFileMSDOSAttributeHidden
The file is hidden.
Definition: OFFileManager.h:101
@ OFFileMSDOSAttributeArchive
The file should be archived.
Definition: OFFileManager.h:109
@ OFFileMSDOSAttributeVolumeLabel
The file is a volume label.
Definition: OFFileManager.h:105
@ OFFileMSDOSAttributeDirectory
The file is a directory.
Definition: OFFileManager.h:107
@ OFFileMSDOSAttributeReadOnly
The file is read-only.
Definition: OFFileManager.h:99
const OFFileAttributeKey OFFilePOSIXPermissions
The POSIX permissions of the file as an OFNumber.
OFFileAmigaProtectionMask
Amiga file protection. This is a bit mask and the values are ORed.
Definition: OFFileManager.h:59
@ OFFileAmigaScript
The file is a script.
Definition: OFFileManager.h:73
@ OFFileAmigaExecuteProtected
The file cannot be executed.
Definition: OFFileManager.h:63
@ OFFileAmigaOtherReadable
The file can be read by others.
Definition: OFFileManager.h:91
@ OFFileAmigaDeleteProtected
The file cannot be deleted.
Definition: OFFileManager.h:61
@ OFFileAmigaOtherExecutable
The file can be executed by others.
Definition: OFFileManager.h:87
@ OFFileAmigaGroupReadable
The file can be read by group.
Definition: OFFileManager.h:83
@ OFFileAmigaOtherWritable
The file can be written to by others.
Definition: OFFileManager.h:89
@ OFFileAmigaGroupExecutable
The file can be executed by the group.
Definition: OFFileManager.h:79
@ OFFileAmigaWriteProtected
The file cannot be written to.
Definition: OFFileManager.h:65
@ OFFileAmigaGroupDeletable
The file can be deleted by the group.
Definition: OFFileManager.h:77
@ OFFileAmigaArchived
The file has not been changed since it was archived.
Definition: OFFileManager.h:69
@ OFFileAmigaReadProtected
The file cannot be read.
Definition: OFFileManager.h:67
@ OFFileAmigaHold
The file is made resident on first execution.
Definition: OFFileManager.h:75
@ OFFileAmigaPure
The file is a reentrant program and can be made resident.
Definition: OFFileManager.h:71
@ OFFileAmigaGroupWritable
The file can be written to by the group.
Definition: OFFileManager.h:81
@ OFFileAmigaOtherDeletable
The file can be deleted by others.
Definition: OFFileManager.h:85
const OFFileAttributeKey OFFileAmigaComment
The Amiga comment as an OFString.
OFConstantString * OFFileAttributeType
The type of a file.
Definition: OFFileManager.h:154
const OFFileAttributeType OFFileTypeBlockSpecial
A block special file.
const OFFileAttributeKey OFFileGroupOwnerAccountID
The account ID of the group owner of the file as an OFNumber.
const OFFileAttributeKey OFFileGroupOwnerAccountName
The account name of the group owner of the file as an OFString.
const OFFileAttributeType OFFileTypeSocket
A socket.
const OFFileAttributeKey OFFileStatusChangeDate
The last status change date of the file as an OFDate.
OFConstantString * OFFileAttributeKey
A key for a file attribute in the file attributes dictionary.
Definition: OFFileManager.h:136
const OFFileAttributeKey OFFileAmigaProtection
The Amiga file protection as an OFNumber.
OFMutableDictionary * OFMutableFileAttributes
A mutable dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition: OFFileManager.h:167
const OFFileAttributeType OFFileTypeRegular
A regular file.
const OFFileAttributeKey OFFileSymbolicLinkDestination
The destination of a symbolic link as an OFString.
const OFFileAttributeKey OFFileType
The type of the file.
const OFFileAttributeKey OFFileModificationDate
The last modification date of the file as an OFDate.
const OFFileAttributeType OFFileTypeCharacterSpecial
A character special file.
const OFFileAttributeKey OFFileSize
The size of the file as an OFNumber.
const OFFileAttributeType OFFileTypeSymbolicLink
A symbolic link.
const OFFileAttributeKey OFFileOwnerAccountID
The account ID of the owner of the file as an OFNumber.
const OFFileAttributeType OFFileTypeUnknown
An unknown file type.
const OFFileAttributeKey OFFileMSDOSAttributes
The MS-DOS attributes as an OFNumber.
OFDictionary * OFFileAttributes
A dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition: OFFileManager.h:160
const OFFileAttributeKey OFFileLastAccessDate
The last access date of the file as an OFDate.
const OFFileAttributeType OFFileTypeDirectory
A directory.
An abstract class for storing objects in an array.
Definition: OFArray.h:110
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A class for storing arbitrary data in an array.
Definition: OFData.h:46
A class for storing, accessing and comparing dates.
Definition: OFDate.h:34
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:84
A class which provides management for files, e.g. reading contents of directories,...
Definition: OFFileManager.h:355
OFFileManager * defaultManager()
Returns the default file manager.
Definition: OFFileManager.m:136
OFIRI * currentDirectoryIRI
The IRI of the current working directory.
Definition: OFFileManager.h:372
OFString * currentDirectoryPath
The path of the current working directory.
Definition: OFFileManager.h:365
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:41
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:48
Provides a way to store a number in an object.
Definition: OFNumber.h:47
The root class for all other classes inside ObjFW.
Definition: OFObject.h:956
A class for handling strings.
Definition: OFString.h:143