JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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//==============================================================================
44class JUCE_API File final
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
132 int64 getSize() const;
133
139 static String descriptionOfSizeInBytes (int64 bytes);
140
141 //==============================================================================
153 const String& getFullPathName() const noexcept { return fullPath; }
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
519 bool moveFileTo (const File& targetLocation) const;
520
531 bool copyFileTo (const File& targetLocation) const;
532
543 bool replaceFileIn (const File& targetLocation) const;
544
558 bool copyDirectoryTo (const File& newDirectory) const;
559
560 //==============================================================================
564 {
565 findDirectories = 1,
566 findFiles = 2,
567 findFilesAndDirectories = 3,
568 ignoreHiddenFiles = 4
569 };
570
571 enum class FollowSymlinks
572 {
574 no,
575
579 noCycles,
580
585 yes
586 };
587
605 Array<File> findChildFiles (int whatToLookFor,
606 bool searchRecursively,
607 const String& wildCardPattern = "*",
608 FollowSymlinks followSymlinks = FollowSymlinks::yes) const;
609
615 int findChildFiles (Array<File>& results, int whatToLookFor,
616 bool searchRecursively, const String& wildCardPattern = "*",
617 FollowSymlinks followSymlinks = FollowSymlinks::yes) const;
618
636 int getNumberOfChildFiles (int whatToLookFor,
637 const String& wildCardPattern = "*") const;
638
642 bool containsSubDirectories() const;
643
644 //==============================================================================
662 std::unique_ptr<FileInputStream> createInputStream() const;
663
695 std::unique_ptr<FileOutputStream> createOutputStream (size_t bufferSize = 0x8000) const;
696
697 //==============================================================================
708 bool loadFileAsData (MemoryBlock& result) const;
709
717 String loadFileAsString() const;
718
722 void readLines (StringArray& destLines) const;
723
724 //==============================================================================
731 bool appendData (const void* dataToAppend,
732 size_t numberOfBytes) const;
733
748 bool replaceWithData (const void* dataToWrite,
749 size_t numberOfBytes) const;
750
764 bool appendText (const String& textToAppend,
765 bool asUnicode = false,
766 bool writeUnicodeHeaderBytes = false,
767 const char* lineEndings = "\r\n") const;
768
785 bool replaceWithText (const String& textToWrite,
786 bool asUnicode = false,
787 bool writeUnicodeHeaderBytes = false,
788 const char* lineEndings = "\r\n") const;
789
793 bool hasIdenticalContentTo (const File& other) const;
794
795 //==============================================================================
802 static void findFileSystemRoots (Array<File>& results);
803
807 String getVolumeLabel() const;
808
812 int getVolumeSerialNumber() const;
813
819 int64 getBytesFreeOnVolume() const;
820
826 int64 getVolumeTotalSize() const;
827
829 bool isOnCDRomDrive() const;
830
836 bool isOnHardDisk() const;
837
842 bool isOnRemovableDrive() const;
843
844 //==============================================================================
856 bool startAsProcess (const String& parameters = String()) const;
857
861 void revealToUser() const;
862
863 //==============================================================================
979
985 static File JUCE_CALLTYPE getSpecialLocation (const SpecialLocationType type);
986
987 //==============================================================================
992 static File createTempFile (StringRef fileNameEnding);
993
994 //==============================================================================
998 static File getCurrentWorkingDirectory();
999
1007 bool setAsCurrentWorkingDirectory() const;
1008
1009 //==============================================================================
1013 static juce_wchar getSeparatorChar();
1014
1018 static StringRef getSeparatorString();
1019
1020 //==============================================================================
1032 static String createLegalFileName (const String& fileNameToFix);
1033
1041 static String createLegalPathName (const String& pathNameToFix);
1042
1044 static bool areFileNamesCaseSensitive();
1045
1047 static bool isAbsolutePath (StringRef path);
1048
1054 static File createFileWithoutCheckingPath (const String& absolutePath) noexcept;
1055
1057 static String addTrailingSeparator (const String& path);
1058
1059 //==============================================================================
1061 bool createSymbolicLink (const File& linkFileToCreate, bool overwriteExisting) const;
1062
1064 bool isSymbolicLink() const;
1065
1069 File getLinkedTarget() const;
1070
1076 static bool createSymbolicLink (const File& linkFileToCreate,
1077 const String& nativePathOfTarget,
1078 bool overwriteExisting);
1079
1082 String getNativeLinkedTarget() const;
1083
1084 #if JUCE_WINDOWS || DOXYGEN
1086 bool createShortcut (const String& description, const File& linkFileToCreate) const;
1087
1089 bool isShortcut() const;
1090 #else
1091
1092 #endif
1093
1094 //==============================================================================
1095 #if JUCE_MAC || JUCE_IOS || DOXYGEN
1097 OSType getMacOSType() const;
1098
1100 bool isBundle() const;
1101 #endif
1102
1103 #if JUCE_MAC || DOXYGEN
1105 void addToDock() const;
1106 #endif
1107
1108 #if JUCE_MAC || JUCE_IOS
1116 static File getContainerForSecurityApplicationGroupIdentifier (const String& appGroup);
1117 #endif
1118
1119 //==============================================================================
1122 {
1123 NaturalFileComparator (bool shouldPutFoldersFirst) noexcept : foldersFirst (shouldPutFoldersFirst) {}
1124
1125 int compareElements (const File& firstFile, const File& secondFile) const
1126 {
1127 if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory()))
1128 return firstFile.isDirectory() ? -1 : 1;
1129
1130 #if NAMES_ARE_CASE_SENSITIVE
1131 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), true);
1132 #else
1133 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), false);
1134 #endif
1135 }
1136
1137 bool foldersFirst;
1138 };
1139
1140 #if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
1141 /* These static objects are deprecated because it's too easy to accidentally use them indirectly
1142 during a static constructor, which leads to very obscure order-of-initialisation bugs.
1143 Use File::getSeparatorChar() and File::getSeparatorString(), and instead of File::nonexistent,
1144 just use File() or {}.
1145 */
1146 [[deprecated]] static const juce_wchar separator;
1147 [[deprecated]] static const StringRef separatorString;
1148 [[deprecated]] static const File nonexistent;
1149 #endif
1150
1151private:
1152 //==============================================================================
1153 String fullPath;
1154
1155 static String parseAbsolutePath (const String&);
1156 String getPathUpToLastSlash() const;
1157 bool isNonEmptyDirectory() const;
1158
1159 Result createDirectoryInternal (const String&) const;
1160 bool copyInternal (const File&) const;
1161 bool moveInternal (const File&) const;
1162 bool replaceInternal (const File&) const;
1163 bool setFileTimesInternal (int64 m, int64 a, int64 c) const;
1164 void getFileTimesInternal (int64& m, int64& a, int64& c) const;
1165 bool setFileReadOnlyInternal (bool) const;
1166 bool setFileExecutableInternal (bool) const;
1167};
1168
1169} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
Represents a local file or directory.
Definition juce_File.h:45
bool isDirectory() const
Checks whether the file is a directory that exists.
OSType getMacOSType() const
OSX ONLY - Finds the OSType of a file from the its resources.
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
Definition juce_File.h:153
~File()=default
Destructor.
SpecialLocationType
A set of types of location that can be passed to the getSpecialLocation() method.
Definition juce_File.h:867
@ userMoviesDirectory
The most likely place where a user might store their movie files.
Definition juce_File.h:884
@ userMusicDirectory
The most likely place where a user might store their music files.
Definition juce_File.h:881
@ tempDirectory
The folder that should be used for temporary files.
Definition juce_File.h:919
@ globalApplicationsDirectory
The directory in which applications normally get installed.
Definition juce_File.h:963
@ userDocumentsDirectory
The user's default documents folder.
Definition juce_File.h:875
@ globalApplicationsDirectoryX86
On a Windows machine, returns the directory in which 32 bit applications normally get installed.
Definition juce_File.h:973
@ currentApplicationFile
Returns this application's location.
Definition juce_File.h:942
@ invokedExecutableFile
Returns the file that was invoked to launch this executable.
Definition juce_File.h:949
@ commonDocumentsDirectory
A place to put documents which are shared by all users of the machine.
Definition juce_File.h:914
@ userApplicationDataDirectory
The folder in which applications store their persistent user-specific settings.
Definition juce_File.h:895
@ userPicturesDirectory
The most likely place where a user might store their picture files.
Definition juce_File.h:887
@ commonApplicationDataDirectory
An equivalent of the userApplicationDataDirectory folder that is shared by all users of the computer,...
Definition juce_File.h:907
@ windowsSystemDirectory
On a Windows machine, returns the location of the Windows/System32 folder.
Definition juce_File.h:956
@ userDesktopDirectory
The folder that contains the user's desktop objects.
Definition juce_File.h:878
@ hostApplicationPath
In a plugin, this will return the path of the host executable.
Definition juce_File.h:952
@ currentExecutableFile
Returns this application's executable file.
Definition juce_File.h:932
@ userHomeDirectory
The user's home folder.
Definition juce_File.h:869
TypesOfFileToFind
Used in file searching, to specify whether to return files, directories, or both.
Definition juce_File.h:564
bool isShortcut() const
Windows ONLY - Returns true if this is a win32 .LNK file.
void addToDock() const
OSX ONLY - Adds this file to the OSX dock.
bool isBundle() const
OSX ONLY - Returns true if this file is actually a bundle.
File()=default
Creates an (invalid) file object.
bool createShortcut(const String &description, const File &linkFileToCreate) const
Windows ONLY - Creates a win32 .LNK shortcut file that links to this file.
A class to hold a resizable block of raw data.
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
Definition juce_Result.h:57
A special array for holding a list of strings.
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition juce_String.h:53
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept
Compares two strings, taking into account textual characteristics like numbers and spaces.
Holds an absolute date and time.
Definition juce_Time.h:37
#define JUCE_CALLTYPE
This macro defines the C calling convention used as the standard for JUCE calls.
typedef int
JUCE Namespace.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
unsigned long long uint64
A platform-independent 64-bit unsigned integer type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
long long int64
A platform-independent 64-bit integer type.