39 : fullPath (
other.fullPath)
45 fullPath = parseAbsolutePath (
newPath);
51 fullPath =
other.fullPath;
56 : fullPath (std::move (
other.fullPath))
62 fullPath = std::move (
other.fullPath);
81 for (
int i = 1; i <
toks.size(); ++i)
85 if (t ==
".." &&
toks[i - 1] !=
"..")
88 toks.removeRange (i - 1, 2);
105static String normaliseSeparators (
const String& path)
137 auto path = normaliseSeparators (removeEllipsis (p.
replaceCharacter (
'/',
'\\')));
155 else if (! path.containsChar (
':'))
176 auto path = normaliseSeparators (removeEllipsis (p));
178 if (path.startsWithChar (
'~'))
197 #if JUCE_DEBUG || JUCE_LOG_ASSERTIONS
198 if (! (path.startsWith (
"./") || path.startsWith (
"../")))
209 #if JUCE_LOG_ASSERTIONS
232#if JUCE_LINUX || JUCE_BSD
233 #define NAMES_ARE_CASE_SENSITIVE 1
238 #if NAMES_ARE_CASE_SENSITIVE
247 #if NAMES_ARE_CASE_SENSITIVE
290 if (
newFile.fullPath == fullPath)
296 #if ! NAMES_ARE_CASE_SENSITIVE
313 if (
newFile.fullPath == fullPath)
319 if (! replaceInternal (
newFile))
331 if (! f.copyFileTo (
newDirectory.getChildFile (f.getFileName())))
335 if (! f.copyDirectoryTo (
newDirectory.getChildFile (f.getFileName())))
345String File::getPathUpToLastSlash()
const
363bool File::isNonEmptyDirectory()
const
393 auto ourPath = getPathUpToLastSlash();
432 auto path = fullPath;
473 path.appendCharPointer (r);
488 if (bytes == 1) { suffix =
" byte"; }
489 else if (bytes < 1024) { suffix =
" bytes"; }
490 else if (bytes < 1024 * 1024) { suffix =
" KB";
divisor = 1024.0; }
491 else if (bytes < 1024 * 1024 * 1024) { suffix =
" MB";
divisor = 1024.0 * 1024.0; }
492 else { suffix =
" GB";
divisor = 1024.0 * 1024.0 * 1024.0; }
505 if (parentDir == *
this)
508 auto r = parentDir.createDirectory();
526 if (parentDir == *
this)
529 auto r = parentDir.createDirectory();
585 results.
add (
di.getFile());
611 bool putNumbersInBrackets)
const
621 if (prefix.trim().endsWithChar (
')'))
623 putNumbersInBrackets =
true;
625 auto openBracks = prefix.lastIndexOfChar (
'(');
639 auto newName = prefix;
641 if (putNumbersInBrackets)
643 newName <<
'(' << ++number <<
')';
655 }
while (f.exists());
668 putNumbersInBrackets);
701 return fullPath[
dotPos] ==
'.';
734 auto fin = std::make_unique<FileInputStream> (*
this);
744 auto fout = std::make_unique<FileOutputStream> (*
this, bufferSize);
746 if (
fout->openedOk())
773 return tempFile.overwriteTargetFileWithTemporary();
780 if (
fout.failedToOpen())
790 return tempFile.overwriteTargetFileWithTemporary();
802 if (
in1.openedOk() &&
in2.openedOk())
804 const int bufferSize = 4096;
833 if (s.isNotEmpty() && s[1] ==
':')
847 const int maxLength = 128;
852 auto lastDot = s.lastIndexOfChar (
'.');
856 s = s.substring (0, maxLength - (len -
lastDot))
861 s = s.substring (0, maxLength);
913 #if NAMES_ARE_CASE_SENSITIVE
981 #if JUCE_MAC || JUCE_LINUX || JUCE_BSD
1018#if JUCE_ALLOW_STATIC_NULL_VARIABLES
1020JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wdeprecated-declarations")
1021JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996)
1025JUCE_END_IGNORE_WARNINGS_GCC_LIKE
1026JUCE_END_IGNORE_WARNINGS_MSVC
1032 : range (0, file.getSize())
1034 openInternal (file, mode, exclusive);
1040 openInternal (file, mode, exclusive);
1055 void runTest()
override
1057 beginTest (
"Reading");
1062 expect (! File().exists());
1063 expect (! File().existsAsFile());
1064 expect (! File().isDirectory());
1066 expect (File (
"/").isDirectory());
1068 expect (
home.isDirectory());
1069 expect (
home.exists());
1070 expect (!
home.existsAsFile());
1075 expect (
home.getVolumeTotalSize() > 1024 * 1024);
1076 expect (
home.getBytesFreeOnVolume() > 0);
1077 expect (!
home.isHidden());
1078 expect (
home.isOnHardDisk());
1079 expect (!
home.isOnCDRomDrive());
1081 expect (
home.setAsCurrentWorkingDirectory());
1105 expect (
roots.size() > 0);
1108 for (
int i = 0; i <
roots.size(); ++i)
1116 beginTest (
"Writing");
1118 auto random = getRandom();
1126 expect (
demoFolder.getParentDirectory() == temp);
1127 expect (temp.isDirectory());
1133 expect (
tempFile.getFileExtension() ==
".txt");
1134 expect (
tempFile.hasFileExtension (
".txt"));
1135 expect (
tempFile.hasFileExtension (
"txt"));
1136 expect (
tempFile.withFileExtension (
"xyz").hasFileExtension (
".xyz"));
1137 expect (
tempFile.withFileExtension (
"xyz").hasFileExtension (
"abc;xyz;foo"));
1138 expect (
tempFile.withFileExtension (
"xyz").hasFileExtension (
"xyz;foo"));
1139 expect (!
tempFile.withFileExtension (
"h").hasFileExtension (
"bar;foo;xx"));
1140 expect (
tempFile.getSiblingFile (
"foo").isAChildOf (temp));
1141 expect (
tempFile.hasWriteAccess());
1143 expect (
home.getChildFile (
".") ==
home);
1144 expect (
home.getChildFile (
"..") ==
home.getParentDirectory());
1145 expect (
home.getChildFile (
".xyz").getFileName() ==
".xyz");
1146 expect (
home.getChildFile (
"..xyz").getFileName() ==
"..xyz");
1147 expect (
home.getChildFile (
"...xyz").getFileName() ==
"...xyz");
1148 expect (
home.getChildFile (
"./xyz") ==
home.getChildFile (
"xyz"));
1149 expect (
home.getChildFile (
"././xyz") ==
home.getChildFile (
"xyz"));
1150 expect (
home.getChildFile (
"../xyz") ==
home.getParentDirectory().getChildFile (
"xyz"));
1151 expect (
home.getChildFile (
".././xyz") ==
home.getParentDirectory().getChildFile (
"xyz"));
1152 expect (
home.getChildFile (
".././xyz/./abc") ==
home.getParentDirectory().getChildFile (
"xyz/abc"));
1153 expect (
home.getChildFile (
"./../xyz") ==
home.getParentDirectory().getChildFile (
"xyz"));
1154 expect (
home.getChildFile (
"a1/a2/a3/./../../a4") ==
home.getChildFile (
"a1/a4"));
1156 expect (! File().hasReadAccess());
1157 expect (! File().hasWriteAccess());
1159 expect (!
tempFile.hasReadAccess());
1163 fo.write (
"0123456789", 10);
1171 expectEquals (
tempFile.loadFileAsString(), String (
"0123456789"));
1172 expect (!
demoFolder.containsSubDirectories());
1180 demoFolder.getNonexistentChildFile (
"tempFolder",
"",
false).createDirectory();
1183 expect (
demoFolder.containsSubDirectories());
1185 expect (
tempFile.hasWriteAccess());
1187 expect (!
tempFile.hasWriteAccess());
1189 expect (
tempFile.hasWriteAccess());
1192 tempFile.setLastModificationTime (t);
1193 Time
t2 =
tempFile.getLastModificationTime();
1194 expect (std::abs ((
int) (
t2.toMilliseconds() - t.toMilliseconds())) <= 1000);
1199 expect (
mb.getSize() == 10);
1200 expect (
mb[0] ==
'0');
1206 expect (
fo.openedOk());
1208 expect (
fo.setPosition (7));
1209 expect (
fo.truncate().wasOk());
1211 fo.write (
"789", 3);
1216 beginTest (
"Memory-mapped files");
1220 expect (
mmf.getSize() == 10);
1221 expect (
mmf.getData() !=
nullptr);
1222 expect (memcmp (
mmf.getData(),
"0123456789", 10) == 0);
1228 expect (
tempFile2.appendData (
"xxxxxxxxxx", 10));
1232 expect (
mmf.getSize() == 10);
1233 expect (
mmf.getData() !=
nullptr);
1234 memcpy (
mmf.getData(),
"abcdefghij", 10);
1239 expect (
mmf.getSize() == 10);
1240 expect (
mmf.getData() !=
nullptr);
1241 expect (memcmp (
mmf.getData(),
"abcdefghij", 10) == 0);
1247 beginTest (
"More writing");
1249 expect (
tempFile.appendData (
"abcdefghij", 10));
1251 expect (
tempFile.replaceWithData (
"abcdefghij", 10));
1268 URL url (
"https://audio.dev/foo/bar/");
1269 expectEquals (url.toString (
false), String (
"https://audio.dev/foo/bar/"));
1270 expectEquals (url.getChildURL (
"x").toString (
false), String (
"https://audio.dev/foo/bar/x"));
1271 expectEquals (url.getParentURL().toString (
false), String (
"https://audio.dev/foo"));
1272 expectEquals (url.getParentURL().getParentURL().toString (
false), String (
"https://audio.dev/"));
1273 expectEquals (url.getParentURL().getParentURL().getParentURL().toString (
false), String (
"https://audio.dev/"));
1274 expectEquals (url.getParentURL().getChildURL (
"x").toString (
false), String (
"https://audio.dev/foo/x"));
1275 expectEquals (url.getParentURL().getParentURL().getParentURL().getChildURL (
"x").toString (
false), String (
"https://audio.dev/x"));
1279 URL url (
"https://audio.dev/foo/bar");
1280 expectEquals (url.toString (
false), String (
"https://audio.dev/foo/bar"));
1281 expectEquals (url.getChildURL (
"x").toString (
false), String (
"https://audio.dev/foo/bar/x"));
1282 expectEquals (url.getParentURL().toString (
false), String (
"https://audio.dev/foo"));
1283 expectEquals (url.getParentURL().getParentURL().toString (
false), String (
"https://audio.dev/"));
1284 expectEquals (url.getParentURL().getParentURL().getParentURL().toString (
false), String (
"https://audio.dev/"));
1285 expectEquals (url.getParentURL().getChildURL (
"x").toString (
false), String (
"https://audio.dev/foo/x"));
1286 expectEquals (url.getParentURL().getParentURL().getParentURL().getChildURL (
"x").toString (
false), String (
"https://audio.dev/x"));
Holds a resizable array of primitive or copy-by-value objects.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
juce_wchar getAndAdvance() noexcept
Returns the character that this pointer is currently pointing to, and then advances the pointer to po...
static juce_wchar toLowerCase(juce_wchar character) noexcept
Converts a character to lower-case.
static bool isDigit(char character) noexcept
Checks whether a character is a digit.
Describes the attributes of a file or folder.
An output stream that writes into a local file.
Represents a local file or directory.
std::unique_ptr< FileOutputStream > createOutputStream(size_t bufferSize=0x8000) const
Creates a stream to write to this file.
bool replaceWithText(const String &textToWrite, bool asUnicode=false, bool writeUnicodeHeaderBytes=false, const char *lineEndings="\r\n") const
Replaces this file's contents with a given text string.
bool isSymbolicLink() const
Returns true if this file is a link or alias that can be followed using getLinkedTarget().
int getNumberOfChildFiles(int whatToLookFor, const String &wildCardPattern="*") const
Searches inside a directory and counts how many files match a wildcard pattern.
bool moveFileTo(const File &targetLocation) const
Moves or renames a file.
bool operator==(const File &) const
Compares the pathnames for two files.
int64 hashCode64() const
Returns a 64-bit hash-code that identifies this file.
bool containsSubDirectories() const
Returns true if this file is a directory that contains one or more subdirectories.
bool isDirectory() const
Checks whether the file is a directory that exists.
Array< File > findChildFiles(int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*", FollowSymlinks followSymlinks=FollowSymlinks::yes) const
Searches this directory for files matching a wildcard pattern.
bool hasIdenticalContentTo(const File &other) const
Attempts to scan the contents of this file and compare it to another file, returning true if this is ...
static StringRef getSeparatorString()
The system-specific file separator character, as a string.
static String createLegalPathName(const String &pathNameToFix)
Returns a version of a path with any illegal characters removed.
static String addTrailingSeparator(const String &path)
Adds a separator character to the end of a path if it doesn't already have one.
String getFileExtension() const
Returns the file's extension.
Time getLastModificationTime() const
Returns the last modification time of this file.
bool existsAsFile() const
Checks whether the file exists and is a file rather than a directory.
bool copyFileTo(const File &targetLocation) const
Copies a file.
int64 getSize() const
Returns the size of the file in bytes.
bool deleteRecursively(bool followSymlinks=false) const
Deletes a file or directory and all its subdirectories.
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
String getFileName() const
Returns the last section of the pathname.
bool replaceWithData(const void *dataToWrite, size_t numberOfBytes) const
Replaces this file's contents with a given block of data.
bool setLastAccessTime(Time newTime) const
Changes the last-access time for this file.
File getChildFile(StringRef relativeOrAbsolutePath) const
Returns a file that represents a relative (or absolute) sub-path of the current one.
void readLines(StringArray &destLines) const
Reads the contents of this file as text and splits it into lines, which are appended to the given Str...
static bool isAbsolutePath(StringRef path)
Returns true if the string seems to be a fully-specified absolute path.
File getSiblingFile(StringRef siblingFileName) const
Returns a file which is in the same directory as this one.
static File getCurrentWorkingDirectory()
Returns the current working directory.
bool createSymbolicLink(const File &linkFileToCreate, bool overwriteExisting) const
Tries to create a symbolic link and returns a boolean to indicate success.
String getFileNameWithoutExtension() const
Returns the last part of the filename, without its file extension.
File getNonexistentSibling(bool putNumbersInBrackets=true) const
Chooses a filename for a sibling file to this one that doesn't already exist.
@ tempDirectory
The folder that should be used for temporary files.
@ currentApplicationFile
Returns this application's location.
@ invokedExecutableFile
Returns the file that was invoked to launch this executable.
@ userApplicationDataDirectory
The folder in which applications store their persistent user-specific settings.
@ currentExecutableFile
Returns this application's executable file.
@ userHomeDirectory
The user's home folder.
static void findFileSystemRoots(Array< File > &results)
Creates a set of files to represent each file root.
String getRelativePathFrom(const File &directoryToBeRelativeTo) const
Creates a relative path that refers to a file relatively to a given directory.
bool appendText(const String &textToAppend, bool asUnicode=false, bool writeUnicodeHeaderBytes=false, const char *lineEndings="\r\n") const
Appends a string to the end of the file.
int hashCode() const
Returns a 32-bit hash-code that identifies this file.
Result create() const
Creates an empty file if it doesn't already exist.
@ findDirectories
Use this flag to indicate that you want to find directories.
@ findFilesAndDirectories
Use this flag to indicate that you want to find both files and directories.
@ findFiles
Use this flag to indicate that you want to find files.
File getNonexistentChildFile(const String &prefix, const String &suffix, bool putNumbersInBrackets=true) const
Chooses a filename relative to this one that doesn't already exist.
bool operator!=(const File &) const
Compares the pathnames for two files.
bool setCreationTime(Time newTime) const
Changes the creation date for this file.
static String descriptionOfSizeInBytes(int64 bytes)
Utility function to convert a file size in bytes to a neat string description.
bool setReadOnly(bool shouldBeReadOnly, bool applyRecursively=false) const
Changes the write-permission of a file or directory.
static File createTempFile(StringRef fileNameEnding)
Returns a temporary file in the system's temp directory.
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
Finds the location of a special type of file or directory, such as a home folder or documents folder.
static bool areFileNamesCaseSensitive()
Indicates whether filenames are case-sensitive on the current operating system.
bool isRoot() const
Checks whether the path of this file represents the root of a file system, irrespective of its existe...
String loadFileAsString() const
Reads a file into memory as a string.
bool operator>(const File &) const
Compares the pathnames for two files.
File getLinkedTarget() const
If this file is a link or alias, this returns the file that it points to.
File getParentDirectory() const
Returns the directory that contains this file or directory.
bool appendData(const void *dataToAppend, size_t numberOfBytes) const
Appends a block of binary data to the end of the file.
std::unique_ptr< FileInputStream > createInputStream() const
Creates a stream to read from this file.
bool operator<(const File &) const
Compares the pathnames for two files.
Time getCreationTime() const
Returns the time that this file was created.
bool setExecutePermission(bool shouldBeExecutable) const
Changes the execute-permissions of a file.
File withFileExtension(StringRef newExtension) const
Returns a version of this file with a different file extension.
static juce_wchar getSeparatorChar()
The system-specific file separator character.
static String createLegalFileName(const String &fileNameToFix)
Returns a version of a filename with any illegal characters removed.
File()=default
Creates an (invalid) file object.
bool deleteFile() const
Deletes a file.
bool replaceFileIn(const File &targetLocation) const
Replaces a file.
bool isAChildOf(const File &potentialParentDirectory) const
Checks whether a file is somewhere inside a directory.
static File createFileWithoutCheckingPath(const String &absolutePath) noexcept
Creates a file that simply contains this string, without doing the sanity-checking that the normal co...
bool startAsProcess(const String ¶meters=String()) const
Launches the file as a process.
String getNativeLinkedTarget() const
This returns the native path that the symbolic link points to.
bool hasFileExtension(StringRef extensionToTest) const
Checks whether the file has a given extension.
bool exists() const
Checks whether the file actually exists.
bool copyDirectoryTo(const File &newDirectory) const
Copies a directory.
bool loadFileAsData(MemoryBlock &result) const
Loads a file's contents into memory as a block of binary data.
bool setLastModificationTime(Time newTime) const
Changes the modification time for this file.
Time getLastAccessTime() const
Returns the last time this file was accessed.
Result createDirectory() const
Creates a new directory for this filename.
File & operator=(const String &newAbsolutePath)
Sets the file based on an absolute pathname.
Very simple container class to hold a pointer to some data on the heap.
static void JUCE_CALLTYPE writeToLog(const String &message)
Writes a string to the current logger.
A class to hold a resizable block of raw data.
MemoryMappedFile(const File &file, AccessMode mode, bool exclusive=false)
Opens a file and maps it to an area of virtual memory.
AccessMode
The read/write flags used when opening a memory mapped file.
@ readWrite
Indicates that the memory can be read and written to - changes that are made will be flushed back to ...
@ readOnly
Indicates that the memory can only be read.
static bool JUCE_CALLTYPE openDocument(const String &documentURL, const String ¶meters)
Tries to launch the OS's default reader application for a given file or URL.
static Random & getSystemRandom() noexcept
The overhead of creating a new Random object is fairly small, but if you want to avoid it,...
A general-purpose range object, that simply represents any linear range with a start and end point.
Allows iterating over files and folders using C++11 range-for syntax.
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
static Result fail(const String &errorMessage) noexcept
Creates a 'failure' result.
static Result ok() noexcept
Creates and returns a 'successful' result.
A special array for holding a list of strings.
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
A simple class for holding temporary references to a string literal or String.
String::CharPointerType text
The text that is referenced.
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
static String repeatedString(StringRef stringToRepeat, int numberOfTimesToRepeat)
Creates a string which is a version of a string repeated and joined together.
int indexOfChar(juce_wchar characterToLookFor) const noexcept
Searches for a character inside this string.
String upToFirstOccurrenceOf(StringRef substringToEndWith, bool includeSubStringInResult, bool ignoreCase) const
Returns the start of this string, up to the first occurrence of a substring.
int length() const noexcept
Returns the number of characters in the string.
bool endsWithChar(juce_wchar character) const noexcept
Tests whether the string ends with a particular character.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
int64 hashCode64() const noexcept
Generates a probably-unique 64-bit hashcode from this string.
bool containsChar(juce_wchar character) const noexcept
Tests whether the string contains a particular character.
String removeCharacters(StringRef charactersToRemove) const
Returns a version of this string with a set of characters removed.
bool endsWithIgnoreCase(StringRef text) const noexcept
Tests whether the string ends with another string.
String dropLastCharacters(int numberToDrop) const
Returns a version of this string with a number of characters removed from the end.
bool contains(StringRef text) const noexcept
Tests whether the string contains another substring.
String trimEnd() const
Returns a copy of this string with any whitespace characters removed from the end.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
int lastIndexOfChar(juce_wchar character) const noexcept
Searches for a character inside this string (working backwards from the end of the string).
String trimCharactersAtEnd(StringRef charactersToTrim) const
Returns a copy of this string, having removed a specified set of characters from its end.
String replaceCharacter(juce_wchar characterToReplace, juce_wchar characterToInsertInstead) const
Returns a string with all occurrences of a character replaced with a different one.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
int hashCode() const noexcept
Generates a probably-unique 32-bit hashcode from this string.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
String fromFirstOccurrenceOf(StringRef substringToStartFrom, bool includeSubStringInResult, bool ignoreCase) const
Returns a section of the string starting from a given substring.
Manages a temporary file, which will be deleted when this object is deleted.
@ useHiddenFile
Indicates that the temporary file should be hidden - i.e.
Holds an absolute date and time.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
int64 toMilliseconds() const noexcept
Returns the time as a number of milliseconds.
This is a base class for classes that perform a unit test.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
long long int64
A platform-independent 64-bit integer type.