| @@ -234,9 +234,8 @@ private: | |||
| void addExistingNotes() | |||
| { | |||
| Array<File> files; | |||
| File::getSpecialLocation (File::userDesktopDirectory).findChildFiles (files, File::findFiles, false, "*.jnote"); | |||
| createNotesForFiles (files); | |||
| createNotesForFiles (File::getSpecialLocation (File::userDesktopDirectory) | |||
| .findChildFiles (File::findFiles, false, "*.jnote")); | |||
| } | |||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MDIDemo) | |||
| @@ -858,15 +858,14 @@ void ProjucerApplication::deleteLogger() | |||
| if (logger != nullptr) | |||
| { | |||
| Array<File> logFiles; | |||
| logger->getLogFile().getParentDirectory().findChildFiles (logFiles, File::findFiles, false); | |||
| auto logFiles = logger->getLogFile().getParentDirectory().findChildFiles (File::findFiles, false); | |||
| if (logFiles.size() > maxNumLogFilesToKeep) | |||
| { | |||
| Array <FileWithTime> files; | |||
| Array<FileWithTime> files; | |||
| for (int i = 0; i < logFiles.size(); ++i) | |||
| files.addUsingDefaultSort (logFiles.getReference(i)); | |||
| for (auto& f : logFiles) | |||
| files.addUsingDefaultSort (f); | |||
| for (int i = 0; i < files.size() - maxNumLogFilesToKeep; ++i) | |||
| files.getReference(i).file.deleteFile(); | |||
| @@ -555,8 +555,7 @@ String LibraryModule::CompileUnit::getFilenameForProxyFile() const | |||
| Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits (ProjectType::Target::Type forTarget) const | |||
| { | |||
| Array<File> files; | |||
| getFolder().findChildFiles (files, File::findFiles, false); | |||
| auto files = getFolder().findChildFiles (File::findFiles, false); | |||
| FileSorter sorter; | |||
| files.sort (sorter); | |||
| @@ -2811,10 +2811,7 @@ private: | |||
| bool xcuserdataMatchesTargets (const File& xcuserdata) const | |||
| { | |||
| Array<File> xcschemeManagementPlists; | |||
| xcuserdata.findChildFiles (xcschemeManagementPlists, File::findFiles, true, "xcschememanagement.plist"); | |||
| for (auto& plist : xcschemeManagementPlists) | |||
| for (auto& plist : xcuserdata.findChildFiles (File::findFiles, true, "xcschememanagement.plist")) | |||
| if (! xcschemeManagementPlistMatchesTargets (plist)) | |||
| return false; | |||
| @@ -199,30 +199,19 @@ public: | |||
| { | |||
| if (source.isDirectory() && dest.createDirectory()) | |||
| { | |||
| Array<File> subFiles; | |||
| source.findChildFiles (subFiles, File::findFiles, false); | |||
| for (int i = 0; i < subFiles.size(); ++i) | |||
| for (auto& f : source.findChildFiles (File::findFiles, false)) | |||
| { | |||
| const File f (subFiles.getReference(i)); | |||
| const File target (dest.getChildFile (f.getFileName())); | |||
| auto target = dest.getChildFile (f.getFileName()); | |||
| filesCreated.add (target); | |||
| if (! f.copyFileTo (target)) | |||
| return false; | |||
| } | |||
| Array<File> subFolders; | |||
| source.findChildFiles (subFolders, File::findDirectories, false); | |||
| for (int i = 0; i < subFolders.size(); ++i) | |||
| { | |||
| const File f (subFolders.getReference(i)); | |||
| for (auto& f : source.findChildFiles (File::findDirectories, false)) | |||
| if (! shouldFolderBeIgnoredWhenCopying (f)) | |||
| if (! copyFolder (f, dest.getChildFile (f.getFileName()))) | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| @@ -80,8 +80,7 @@ void AppearanceSettings::refreshPresetSchemeList() | |||
| writeDefaultSchemeFile (BinaryData::colourscheme_dark_xml, "Default (Dark)"); | |||
| writeDefaultSchemeFile (BinaryData::colourscheme_light_xml, "Default (Light)"); | |||
| Array<File> newSchemes; | |||
| getSchemesFolder().findChildFiles (newSchemes, File::findFiles, false, String ("*") + getSchemeFileSuffix()); | |||
| auto newSchemes = getSchemesFolder().findChildFiles (File::findFiles, false, String ("*") + getSchemeFileSuffix()); | |||
| if (newSchemes != presetSchemeFiles) | |||
| { | |||
| @@ -146,11 +146,10 @@ int main (int argc, char* argv[]) | |||
| << " from files in " << sourceDirectory.getFullPathName() | |||
| << "..." << std::endl << std::endl; | |||
| Array<File> files; | |||
| sourceDirectory.findChildFiles (files, File::findFiles, true, | |||
| (argc > 4) ? argv[4] : "*"); | |||
| auto files = sourceDirectory.findChildFiles (File::findFiles, true, | |||
| (argc > 4) ? argv[4] : "*"); | |||
| if (files.size() == 0) | |||
| if (files.isEmpty()) | |||
| { | |||
| std::cout << "Didn't find any source files in: " | |||
| << sourceDirectory.getFullPathName() << std::endl << std::endl; | |||
| @@ -438,15 +438,14 @@ struct ModuleHandle : public ReferenceCountedObject | |||
| ok = true; | |||
| Array<File> vstXmlFiles; | |||
| file | |||
| #if JUCE_MAC | |||
| .getChildFile ("Contents") | |||
| .getChildFile ("Resources") | |||
| #endif | |||
| .findChildFiles (vstXmlFiles, File::findFiles, false, "*.vstxml"); | |||
| if (vstXmlFiles.size() > 0) | |||
| auto vstXmlFiles = file | |||
| #if JUCE_MAC | |||
| .getChildFile ("Contents") | |||
| .getChildFile ("Resources") | |||
| #endif | |||
| .findChildFiles (File::findFiles, false, "*.vstxml"); | |||
| if (! vstXmlFiles.isEmpty()) | |||
| vstXml.reset (XmlDocument::parse (vstXmlFiles.getReference(0))); | |||
| } | |||
| } | |||
| @@ -204,13 +204,8 @@ void KnownPluginList::scanAndAddDragAndDroppedFiles (AudioPluginFormatManager& f | |||
| { | |||
| StringArray s; | |||
| { | |||
| Array<File> subFiles; | |||
| f.findChildFiles (subFiles, File::findFilesAndDirectories, false); | |||
| for (auto& subFile : subFiles) | |||
| s.add (subFile.getFullPathName()); | |||
| } | |||
| for (auto& subFile : f.findChildFiles (File::findFilesAndDirectories, false)) | |||
| s.add (subFile.getFullPathName()); | |||
| scanAndAddDragAndDroppedFiles (formatManager, s, typesFound); | |||
| } | |||
| @@ -247,13 +247,8 @@ bool File::setReadOnly (const bool shouldBeReadOnly, | |||
| bool worked = true; | |||
| if (applyRecursively && isDirectory()) | |||
| { | |||
| Array<File> subFiles; | |||
| findChildFiles (subFiles, File::findFilesAndDirectories, false); | |||
| for (auto& f : subFiles) | |||
| for (auto& f : findChildFiles (File::findFilesAndDirectories, false)) | |||
| worked = f.setReadOnly (shouldBeReadOnly, true) && worked; | |||
| } | |||
| return setFileReadOnlyInternal (shouldBeReadOnly) && worked; | |||
| } | |||
| @@ -268,13 +263,8 @@ bool File::deleteRecursively() const | |||
| bool worked = true; | |||
| if (isDirectory()) | |||
| { | |||
| Array<File> subFiles; | |||
| findChildFiles (subFiles, File::findFilesAndDirectories, false); | |||
| for (auto& f : subFiles) | |||
| for (auto& f : findChildFiles (File::findFilesAndDirectories, false)) | |||
| worked = f.deleteRecursively() && worked; | |||
| } | |||
| return deleteFile() && worked; | |||
| } | |||
| @@ -321,17 +311,11 @@ bool File::copyDirectoryTo (const File& newDirectory) const | |||
| { | |||
| if (isDirectory() && newDirectory.createDirectory()) | |||
| { | |||
| Array<File> subFiles; | |||
| findChildFiles (subFiles, File::findFiles, false); | |||
| for (auto& f : subFiles) | |||
| for (auto& f : findChildFiles (File::findFiles, false)) | |||
| if (! f.copyFileTo (newDirectory.getChildFile (f.getFileName()))) | |||
| return false; | |||
| subFiles.clear(); | |||
| findChildFiles (subFiles, File::findDirectories, false); | |||
| for (auto& f : subFiles) | |||
| for (auto& f : findChildFiles (File::findDirectories, false)) | |||
| if (! f.copyDirectoryTo (newDirectory.getChildFile (f.getFileName()))) | |||
| return false; | |||
| @@ -561,14 +545,18 @@ void File::readLines (StringArray& destLines) const | |||
| } | |||
| //============================================================================== | |||
| int File::findChildFiles (Array<File>& results, | |||
| const int whatToLookFor, | |||
| const bool searchRecursively, | |||
| const String& wildCardPattern) const | |||
| Array<File> File::findChildFiles (int whatToLookFor, bool searchRecursively, const String& wildcard) const | |||
| { | |||
| Array<File> results; | |||
| findChildFiles (results, whatToLookFor, searchRecursively, wildcard); | |||
| return results; | |||
| } | |||
| int File::findChildFiles (Array<File>& results, int whatToLookFor, bool searchRecursively, const String& wildcard) const | |||
| { | |||
| int total = 0; | |||
| for (DirectoryIterator di (*this, searchRecursively, wildCardPattern, whatToLookFor); di.next();) | |||
| for (DirectoryIterator di (*this, searchRecursively, wildcard, whatToLookFor); di.next();) | |||
| { | |||
| results.add (di.getFile()); | |||
| ++total; | |||
| @@ -1062,18 +1050,8 @@ public: | |||
| expect (demoFolder.isDirectory()); | |||
| expect (demoFolder.getParentDirectory() == temp); | |||
| expect (temp.isDirectory()); | |||
| { | |||
| Array<File> files; | |||
| temp.findChildFiles (files, File::findFilesAndDirectories, false, "*"); | |||
| expect (files.contains (demoFolder)); | |||
| } | |||
| { | |||
| Array<File> files; | |||
| temp.findChildFiles (files, File::findDirectories, true, "*.folder"); | |||
| expect (files.contains (demoFolder)); | |||
| } | |||
| expect (temp.findChildFiles (File::findFilesAndDirectories, false, "*").contains (demoFolder)); | |||
| expect (temp.findChildFiles (File::findDirectories, true, "*.folder").contains (demoFolder)); | |||
| File tempFile (demoFolder.getNonexistentChildFile ("test", ".txt", false)); | |||
| @@ -544,28 +544,33 @@ public: | |||
| ignoreHiddenFiles = 4 /**< Add this flag to avoid returning any hidden files in the results. */ | |||
| }; | |||
| /** Searches inside a directory for files matching a wildcard pattern. | |||
| /** Searches this directory for files matching a wildcard pattern. | |||
| Assuming that this file is a directory, this method will search it | |||
| for either files or subdirectories whose names match a filename pattern. | |||
| Note that the order in which files are returned is completely undefined! | |||
| @param results an array to which File objects will be added for the | |||
| files that the search comes up with | |||
| @param whatToLookFor a value from the TypesOfFileToFind enum, specifying whether to | |||
| return files, directories, or both. If the ignoreHiddenFiles flag | |||
| is also added to this value, hidden files won't be returned | |||
| @param searchRecursively if true, all subdirectories will be recursed into to do | |||
| an exhaustive search | |||
| @param wildCardPattern the filename pattern to search for, e.g. "*.txt" | |||
| @returns the number of results that have been found | |||
| @returns the set of files that were found | |||
| @see getNumberOfChildFiles, DirectoryIterator | |||
| */ | |||
| int findChildFiles (Array<File>& results, | |||
| int whatToLookFor, | |||
| bool searchRecursively, | |||
| const String& wildCardPattern = "*") const; | |||
| Array<File> findChildFiles (int whatToLookFor, | |||
| bool searchRecursively, | |||
| const String& wildCardPattern = "*") const; | |||
| /** Searches inside a directory for files matching a wildcard pattern. | |||
| Note that there's a newer, better version of this method which returns the results | |||
| array, and in almost all cases, you should use that one instead! This one is kept around | |||
| mainly for legacy code to use. | |||
| */ | |||
| int findChildFiles (Array<File>& results, int whatToLookFor, | |||
| bool searchRecursively, const String& wildCardPattern = "*") const; | |||
| /** Searches inside a directory and counts how many files match a wildcard pattern. | |||
| @@ -132,6 +132,13 @@ void FileSearchPath::removeNonExistentPaths() | |||
| directories.remove (i); | |||
| } | |||
| Array<File> FileSearchPath::findChildFiles (int whatToLookFor, bool recurse, const String& wildcard) const | |||
| { | |||
| Array<File> results; | |||
| findChildFiles (results, whatToLookFor, recurse, wildcard); | |||
| return results; | |||
| } | |||
| int FileSearchPath::findChildFiles (Array<File>& results, int whatToLookFor, | |||
| bool recurse, const String& wildcard) const | |||
| { | |||
| @@ -114,10 +114,9 @@ public: | |||
| //============================================================================== | |||
| /** Searches the path for a wildcard. | |||
| This will search all the directories in the search path in order, adding any | |||
| matching files to the results array. | |||
| This will search all the directories in the search path in order and return | |||
| an array of the files that were found. | |||
| @param results an array to append the results to | |||
| @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying whether to | |||
| return files, directories, or both. | |||
| @param searchRecursively whether to recursively search the subdirectories too | |||
| @@ -125,6 +124,15 @@ public: | |||
| @returns the number of files added to the array | |||
| @see File::findChildFiles | |||
| */ | |||
| Array<File> findChildFiles (int whatToLookFor, | |||
| bool searchRecursively, | |||
| const String& wildCardPattern = "*") const; | |||
| /** Searches the path for a wildcard. | |||
| Note that there's a newer, better version of this method which returns the results | |||
| array, and in almost all cases, you should use that one instead! This one is kept around | |||
| mainly for legacy code to use. | |||
| */ | |||
| int findChildFiles (Array<File>& results, | |||
| int whatToLookFor, | |||
| bool searchRecursively, | |||
| @@ -106,12 +106,8 @@ StringArray Font::findAllTypefaceNames() | |||
| { | |||
| StringArray results; | |||
| Array<File> fonts; | |||
| File ("/system/fonts").findChildFiles (fonts, File::findFiles, false, "*.ttf"); | |||
| for (int i = 0; i < fonts.size(); ++i) | |||
| results.addIfNotAlreadyThere (fonts.getReference(i).getFileNameWithoutExtension() | |||
| .upToLastOccurrenceOf ("-", false, false)); | |||
| for (auto& f : File ("/system/fonts").findChildFiles (File::findFiles, false, "*.ttf")) | |||
| results.addIfNotAlreadyThere (f.getFileNameWithoutExtension().upToLastOccurrenceOf ("-", false, false)); | |||
| return results; | |||
| } | |||
| @@ -120,12 +116,8 @@ StringArray Font::findAllTypefaceStyles (const String& family) | |||
| { | |||
| StringArray results ("Regular"); | |||
| Array<File> fonts; | |||
| File ("/system/fonts").findChildFiles (fonts, File::findFiles, false, family + "-*.ttf"); | |||
| for (int i = 0; i < fonts.size(); ++i) | |||
| results.addIfNotAlreadyThere (fonts.getReference(i).getFileNameWithoutExtension() | |||
| .fromLastOccurrenceOf ("-", false, false)); | |||
| for (auto& f : File ("/system/fonts").findChildFiles (File::findFiles, false, family + "-*.ttf")) | |||
| results.addIfNotAlreadyThere (f.getFileNameWithoutExtension().fromLastOccurrenceOf ("-", false, false)); | |||
| return results; | |||
| } | |||
| @@ -577,14 +577,8 @@ void FileBrowserComponent::getDefaultRoots (StringArray& rootNames, StringArray& | |||
| rootPaths.add ({}); | |||
| rootNames.add ({}); | |||
| Array<File> volumes; | |||
| File vol ("/Volumes"); | |||
| vol.findChildFiles (volumes, File::findDirectories, false); | |||
| for (int i = 0; i < volumes.size(); ++i) | |||
| for (auto& volume : File ("/Volumes").findChildFiles (File::findDirectories, false)) | |||
| { | |||
| const File& volume = volumes.getReference(i); | |||
| if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.')) | |||
| { | |||
| rootPaths.add (volume.getFullPathName()); | |||