LMMS
Loading...
Searching...
No Matches
juce_File.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26#if ! DOXYGEN && (JUCE_MAC || JUCE_IOS)
27 using OSType = unsigned int;
28#endif
29
30//==============================================================================
45{
46public:
47 //==============================================================================
55 File() = default;
56
67 File (const String& absolutePath);
68
70 File (const File&);
71
73 ~File() = default;
74
85 File& operator= (const String& newAbsolutePath);
86
88 File& operator= (const File& otherFile);
89
91 File (File&&) noexcept;
92
94 File& operator= (File&&) noexcept;
95
96 //==============================================================================
102 bool exists() const;
103
110 bool existsAsFile() const;
111
118 bool isDirectory() const;
119
126 bool isRoot() const;
127
133
140
141 //==============================================================================
154
168 String getFileName() const;
169
185 String getRelativePathFrom (const File& directoryToBeRelativeTo) const;
186
187 //==============================================================================
196 String getFileExtension() const;
197
209 bool hasFileExtension (StringRef extensionToTest) const;
210
221 File withFileExtension (StringRef newExtension) const;
222
229 String getFileNameWithoutExtension() const;
230
231 //==============================================================================
237 int hashCode() const;
238
244 int64 hashCode64() const;
245
246 //==============================================================================
261 File getChildFile (StringRef relativeOrAbsolutePath) const;
262
269 File getSiblingFile (StringRef siblingFileName) const;
270
271 //==============================================================================
279 File getParentDirectory() const;
280
290 bool isAChildOf (const File& potentialParentDirectory) const;
291
292 //==============================================================================
310 File getNonexistentChildFile (const String& prefix,
311 const String& suffix,
312 bool putNumbersInBrackets = true) const;
313
323 File getNonexistentSibling (bool putNumbersInBrackets = true) const;
324
325 //==============================================================================
327 bool operator== (const File&) const;
329 bool operator!= (const File&) const;
331 bool operator< (const File&) const;
333 bool operator> (const File&) const;
334
335 //==============================================================================
343 bool hasWriteAccess() const;
344
349 bool hasReadAccess() const;
350
360 bool setReadOnly (bool shouldBeReadOnly,
361 bool applyRecursively = false) const;
362
368 bool setExecutePermission (bool shouldBeExecutable) const;
369
373 bool isHidden() const;
374
381 uint64 getFileIdentifier() const;
382
383 //==============================================================================
389 Time getLastModificationTime() const;
390
396 Time getLastAccessTime() const;
397
403 Time getCreationTime() const;
404
411 bool setLastModificationTime (Time newTime) const;
412
419 bool setLastAccessTime (Time newTime) const;
420
427 bool setCreationTime (Time newTime) const;
428
435 String getVersion() const;
436
437 //==============================================================================
452 Result create() const;
453
463 Result createDirectory() const;
464
477 bool deleteFile() const;
478
491 bool deleteRecursively (bool followSymlinks = false) const;
492
499 bool moveToTrash() const;
500
515 bool moveFileTo (const File& targetLocation) const;
516
525 bool copyFileTo (const File& targetLocation) const;
526
537 bool replaceFileIn (const File& targetLocation) const;
538
552 bool copyDirectoryTo (const File& newDirectory) const;
553
554 //==============================================================================
564
565 enum class FollowSymlinks
566 {
569
573 noCycles,
574
580 };
581
599 Array<File> findChildFiles (int whatToLookFor,
600 bool searchRecursively,
601 const String& wildCardPattern = "*",
602 FollowSymlinks followSymlinks = FollowSymlinks::yes) const;
603
609 int findChildFiles (Array<File>& results, int whatToLookFor,
610 bool searchRecursively, const String& wildCardPattern = "*",
611 FollowSymlinks followSymlinks = FollowSymlinks::yes) const;
612
630 int getNumberOfChildFiles (int whatToLookFor,
631 const String& wildCardPattern = "*") const;
632
636 bool containsSubDirectories() const;
637
638 //==============================================================================
656 std::unique_ptr<FileInputStream> createInputStream() const;
657
689 std::unique_ptr<FileOutputStream> createOutputStream (size_t bufferSize = 0x8000) const;
690
691 //==============================================================================
702 bool loadFileAsData (MemoryBlock& result) const;
703
711 String loadFileAsString() const;
712
716 void readLines (StringArray& destLines) const;
717
718 //==============================================================================
725 bool appendData (const void* dataToAppend,
726 size_t numberOfBytes) const;
727
742 bool replaceWithData (const void* dataToWrite,
743 size_t numberOfBytes) const;
744
758 bool appendText (const String& textToAppend,
759 bool asUnicode = false,
760 bool writeUnicodeHeaderBytes = false,
761 const char* lineEndings = "\r\n") const;
762
779 bool replaceWithText (const String& textToWrite,
780 bool asUnicode = false,
781 bool writeUnicodeHeaderBytes = false,
782 const char* lineEndings = "\r\n") const;
783
787 bool hasIdenticalContentTo (const File& other) const;
788
789 //==============================================================================
796 static void findFileSystemRoots (Array<File>& results);
797
801 String getVolumeLabel() const;
802
806 int getVolumeSerialNumber() const;
807
813 int64 getBytesFreeOnVolume() const;
814
820 int64 getVolumeTotalSize() const;
821
823 bool isOnCDRomDrive() const;
824
830 bool isOnHardDisk() const;
831
836 bool isOnRemovableDrive() const;
837
838 //==============================================================================
850 bool startAsProcess (const String& parameters = String()) const;
851
855 void revealToUser() const;
856
857 //==============================================================================
861 {
864
870
873
876
879
882
890
902
909
914
927
937
944
947
948 #if JUCE_WINDOWS || DOXYGEN
950 windowsSystemDirectory,
951 #endif
952
958
959 #if JUCE_WINDOWS || DOXYGEN
967 globalApplicationsDirectoryX86,
968
970 windowsLocalAppData
971 #endif
972 };
973
979 static File JUCE_CALLTYPE getSpecialLocation (const SpecialLocationType type);
980
981 //==============================================================================
986 static File createTempFile (StringRef fileNameEnding);
987
988 //==============================================================================
992 static File getCurrentWorkingDirectory();
993
1001 bool setAsCurrentWorkingDirectory() const;
1002
1003 //==============================================================================
1007 static juce_wchar getSeparatorChar();
1008
1012 static StringRef getSeparatorString();
1013
1014 //==============================================================================
1026 static String createLegalFileName (const String& fileNameToFix);
1027
1035 static String createLegalPathName (const String& pathNameToFix);
1036
1038 static bool areFileNamesCaseSensitive();
1039
1041 static bool isAbsolutePath (StringRef path);
1042
1048 static File createFileWithoutCheckingPath (const String& absolutePath) noexcept;
1049
1051 static String addTrailingSeparator (const String& path);
1052
1053 //==============================================================================
1055 bool createSymbolicLink (const File& linkFileToCreate, bool overwriteExisting) const;
1056
1058 bool isSymbolicLink() const;
1059
1063 File getLinkedTarget() const;
1064
1070 static bool createSymbolicLink (const File& linkFileToCreate,
1071 const String& nativePathOfTarget,
1072 bool overwriteExisting);
1073
1076 String getNativeLinkedTarget() const;
1077
1078 #if JUCE_WINDOWS || DOXYGEN
1080 bool createShortcut (const String& description, const File& linkFileToCreate) const;
1081
1083 bool isShortcut() const;
1084 #else
1085
1086 #endif
1087
1088 //==============================================================================
1089 #if JUCE_MAC || JUCE_IOS || DOXYGEN
1091 OSType getMacOSType() const;
1092
1094 bool isBundle() const;
1095 #endif
1096
1097 #if JUCE_MAC || DOXYGEN
1099 void addToDock() const;
1100 #endif
1101
1102 #if JUCE_MAC || JUCE_IOS
1110 static File getContainerForSecurityApplicationGroupIdentifier (const String& appGroup);
1111 #endif
1112
1113 //==============================================================================
1116 {
1117 NaturalFileComparator (bool shouldPutFoldersFirst) noexcept : foldersFirst (shouldPutFoldersFirst) {}
1118
1119 int compareElements (const File& firstFile, const File& secondFile) const
1120 {
1121 if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory()))
1122 return firstFile.isDirectory() ? -1 : 1;
1123
1124 #if NAMES_ARE_CASE_SENSITIVE
1125 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), true);
1126 #else
1127 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), false);
1128 #endif
1129 }
1130
1132 };
1133
1134 #if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
1135 /* These static objects are deprecated because it's too easy to accidentally use them indirectly
1136 during a static constructor, which leads to very obscure order-of-initialisation bugs.
1137 Use File::getSeparatorChar() and File::getSeparatorString(), and instead of File::nonexistent,
1138 just use File() or {}.
1139 */
1140 [[deprecated]] static const juce_wchar separator;
1141 [[deprecated]] static const StringRef separatorString;
1142 [[deprecated]] static const File nonexistent;
1143 #endif
1144
1145private:
1146 //==============================================================================
1148
1149 static String parseAbsolutePath (const String&);
1151
1152 Result createDirectoryInternal (const String&) const;
1153 bool copyInternal (const File&) const;
1154 bool moveInternal (const File&) const;
1155 bool replaceInternal (const File&) const;
1156 bool setFileTimesInternal (int64 m, int64 a, int64 c) const;
1157 void getFileTimesInternal (int64& m, int64& a, int64& c) const;
1158 bool setFileReadOnlyInternal (bool) const;
1159 bool setFileExecutableInternal (bool) const;
1160};
1161
1162} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
#define final
Definition DistrhoDefines.h:74
uint8_t a
Definition Spc_Cpu.h:141
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Definition juce_Array.h:56
Definition juce_File.h:45
bool copyInternal(const File &) const
Definition juce_linux_CommonFile.cpp:26
bool isDirectory() const
Definition juce_posix_SharedCode.h:238
bool existsAsFile() const
Definition juce_posix_SharedCode.h:252
int64 getSize() const
Definition juce_posix_SharedCode.h:257
String fullPath
Definition juce_File.h:1147
const String & getFullPathName() const noexcept
Definition juce_File.h:153
String getPathUpToLastSlash() const
Definition juce_File.cpp:345
~File()=default
static String parseAbsolutePath(const String &)
Definition juce_File.cpp:130
SpecialLocationType
Definition juce_File.h:861
@ userMoviesDirectory
Definition juce_File.h:878
@ userMusicDirectory
Definition juce_File.h:875
@ tempDirectory
Definition juce_File.h:913
@ globalApplicationsDirectory
Definition juce_File.h:957
@ userDocumentsDirectory
Definition juce_File.h:869
@ currentApplicationFile
Definition juce_File.h:936
@ invokedExecutableFile
Definition juce_File.h:943
@ commonDocumentsDirectory
Definition juce_File.h:908
@ userApplicationDataDirectory
Definition juce_File.h:889
@ userPicturesDirectory
Definition juce_File.h:881
@ commonApplicationDataDirectory
Definition juce_File.h:901
@ userDesktopDirectory
Definition juce_File.h:872
@ hostApplicationPath
Definition juce_File.h:946
@ currentExecutableFile
Definition juce_File.h:926
@ userHomeDirectory
Definition juce_File.h:863
bool replaceInternal(const File &) const
Definition juce_posix_SharedCode.h:420
TypesOfFileToFind
Definition juce_File.h:558
@ ignoreHiddenFiles
Definition juce_File.h:562
@ findDirectories
Definition juce_File.h:559
@ findFilesAndDirectories
Definition juce_File.h:561
@ findFiles
Definition juce_File.h:560
static String descriptionOfSizeInBytes(int64 bytes)
Definition juce_File.cpp:475
FollowSymlinks
Definition juce_File.h:566
bool moveInternal(const File &) const
Definition juce_posix_SharedCode.h:404
bool isRoot() const
Definition juce_File.cpp:125
void getFileTimesInternal(int64 &m, int64 &a, int64 &c) const
Definition juce_posix_SharedCode.h:325
bool setFileReadOnlyInternal(bool) const
Definition juce_posix_SharedCode.h:314
bool setFileExecutableInternal(bool) const
Definition juce_posix_SharedCode.h:320
bool setFileTimesInternal(int64 m, int64 a, int64 c) const
Definition juce_posix_SharedCode.h:351
File()=default
bool exists() const
Definition juce_posix_SharedCode.h:246
Result createDirectoryInternal(const String &) const
Definition juce_posix_SharedCode.h:425
Definition juce_MemoryBlock.h:33
Definition juce_Result.h:57
Definition juce_StringArray.h:35
Definition juce_String.h:53
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept
Definition juce_String.cpp:700
Definition juce_StringRef.h:62
Definition juce_Time.h:37
unsigned * m
Definition inflate.c:1559
#define JUCE_CALLTYPE
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
@ no
Definition juce_AlertWindow.cpp:567
@ yes
Definition juce_AlertWindow.cpp:567
static File createTempFile(const File &parentDirectory, String name, const String &suffix, int optionFlags)
Definition juce_TemporaryFile.cpp:43
unsigned long long uint64
Definition juce_MathsFunctions.h:56
long long int64
Definition juce_MathsFunctions.h:54
wchar_t juce_wchar
Definition juce_CharacterFunctions.h:42
bool foldersFirst
Definition juce_File.h:1131
NaturalFileComparator(bool shouldPutFoldersFirst) noexcept
Definition juce_File.h:1117
int compareElements(const File &firstFile, const File &secondFile) const
Definition juce_File.h:1119
return c
Definition crypt.c:175
int result
Definition process.c:1455
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137