OpenShot Audio Library | OpenShotAudio  0.3.0
juce_File.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
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 
23 namespace juce
24 {
25 
26 //==============================================================================
40 class JUCE_API File final
41 {
42 public:
43  //==============================================================================
51  File() = default;
52 
63  File (const String& absolutePath);
64 
66  File (const File&);
67 
69  ~File() = default;
70 
81  File& operator= (const String& newAbsolutePath);
82 
84  File& operator= (const File& otherFile);
85 
87  File (File&&) noexcept;
88 
90  File& operator= (File&&) noexcept;
91 
92  //==============================================================================
98  bool exists() const;
99 
106  bool existsAsFile() const;
107 
114  bool isDirectory() const;
115 
122  bool isRoot() const;
123 
128  int64 getSize() const;
129 
135  static String descriptionOfSizeInBytes (int64 bytes);
136 
137  //==============================================================================
149  const String& getFullPathName() const noexcept { return fullPath; }
150 
164  String getFileName() const;
165 
181  String getRelativePathFrom (const File& directoryToBeRelativeTo) const;
182 
183  //==============================================================================
192  String getFileExtension() const;
193 
205  bool hasFileExtension (StringRef extensionToTest) const;
206 
217  File withFileExtension (StringRef newExtension) const;
218 
225  String getFileNameWithoutExtension() const;
226 
227  //==============================================================================
233  int hashCode() const;
234 
240  int64 hashCode64() const;
241 
242  //==============================================================================
257  File getChildFile (StringRef relativeOrAbsolutePath) const;
258 
265  File getSiblingFile (StringRef siblingFileName) const;
266 
267  //==============================================================================
275  File getParentDirectory() const;
276 
286  bool isAChildOf (const File& potentialParentDirectory) const;
287 
288  //==============================================================================
306  File getNonexistentChildFile (const String& prefix,
307  const String& suffix,
308  bool putNumbersInBrackets = true) const;
309 
319  File getNonexistentSibling (bool putNumbersInBrackets = true) const;
320 
321  //==============================================================================
323  bool operator== (const File&) const;
325  bool operator!= (const File&) const;
327  bool operator< (const File&) const;
329  bool operator> (const File&) const;
330 
331  //==============================================================================
339  bool hasWriteAccess() const;
340 
350  bool setReadOnly (bool shouldBeReadOnly,
351  bool applyRecursively = false) const;
352 
358  bool setExecutePermission (bool shouldBeExecutable) const;
359 
363  bool isHidden() const;
364 
371  uint64 getFileIdentifier() const;
372 
373  //==============================================================================
379  Time getLastModificationTime() const;
380 
386  Time getLastAccessTime() const;
387 
393  Time getCreationTime() const;
394 
401  bool setLastModificationTime (Time newTime) const;
402 
409  bool setLastAccessTime (Time newTime) const;
410 
417  bool setCreationTime (Time newTime) const;
418 
426 
427  //==============================================================================
442  Result create() const;
443 
453  Result createDirectory() const;
454 
467  bool deleteFile() const;
468 
481  bool deleteRecursively (bool followSymlinks = false) const;
482 
489  bool moveToTrash() const;
490 
505  bool moveFileTo (const File& targetLocation) const;
506 
515  bool copyFileTo (const File& targetLocation) const;
516 
527  bool replaceFileIn (const File& targetLocation) const;
528 
542  bool copyDirectoryTo (const File& newDirectory) const;
543 
544  //==============================================================================
548  {
549  findDirectories = 1,
550  findFiles = 2,
551  findFilesAndDirectories = 3,
552  ignoreHiddenFiles = 4
553  };
554 
571  Array<File> findChildFiles (int whatToLookFor,
572  bool searchRecursively,
573  const String& wildCardPattern = "*") const;
574 
580  int findChildFiles (Array<File>& results, int whatToLookFor,
581  bool searchRecursively, const String& wildCardPattern = "*") const;
582 
599  int getNumberOfChildFiles (int whatToLookFor,
600  const String& wildCardPattern = "*") const;
601 
605  bool containsSubDirectories() const;
606 
607  //==============================================================================
625  FileInputStream* createInputStream() const;
626 
658  FileOutputStream* createOutputStream (size_t bufferSize = 0x8000) const;
659 
660  //==============================================================================
671  bool loadFileAsData (MemoryBlock& result) const;
672 
680  String loadFileAsString() const;
681 
685  void readLines (StringArray& destLines) const;
686 
687  //==============================================================================
694  bool appendData (const void* dataToAppend,
695  size_t numberOfBytes) const;
696 
711  bool replaceWithData (const void* dataToWrite,
712  size_t numberOfBytes) const;
713 
727  bool appendText (const String& textToAppend,
728  bool asUnicode = false,
729  bool writeUnicodeHeaderBytes = false,
730  const char* lineEndings = "\r\n") const;
731 
748  bool replaceWithText (const String& textToWrite,
749  bool asUnicode = false,
750  bool writeUnicodeHeaderBytes = false,
751  const char* lineEndings = "\r\n") const;
752 
756  bool hasIdenticalContentTo (const File& other) const;
757 
758  //==============================================================================
765  static void findFileSystemRoots (Array<File>& results);
766 
771 
776 
782  int64 getBytesFreeOnVolume() const;
783 
789  int64 getVolumeTotalSize() const;
790 
792  bool isOnCDRomDrive() const;
793 
799  bool isOnHardDisk() const;
800 
805  bool isOnRemovableDrive() const;
806 
807  //==============================================================================
819  bool startAsProcess (const String& parameters = String()) const;
820 
824  void revealToUser() const;
825 
826  //==============================================================================
830  {
833 
839 
842 
845 
848 
851 
859 
871 
878 
883 
896 
906 
913 
916 
917  #if JUCE_WINDOWS || DOXYGEN
919  windowsSystemDirectory,
920  #endif
921 
927 
928  #if JUCE_WINDOWS || DOXYGEN
936  globalApplicationsDirectoryX86
937  #endif
938  };
939 
945  static File JUCE_CALLTYPE getSpecialLocation (const SpecialLocationType type);
946 
947  //==============================================================================
952  static File createTempFile (StringRef fileNameEnding);
953 
954  //==============================================================================
959 
968 
969  //==============================================================================
973  static juce_wchar getSeparatorChar();
974 
979 
980  //==============================================================================
992  static String createLegalFileName (const String& fileNameToFix);
993 
1001  static String createLegalPathName (const String& pathNameToFix);
1002 
1004  static bool areFileNamesCaseSensitive();
1005 
1007  static bool isAbsolutePath (StringRef path);
1008 
1014  static File createFileWithoutCheckingPath (const String& absolutePath) noexcept;
1015 
1017  static String addTrailingSeparator (const String& path);
1018 
1019  //==============================================================================
1021  bool createSymbolicLink (const File& linkFileToCreate, bool overwriteExisting) const;
1022 
1024  bool isSymbolicLink() const;
1025 
1029  File getLinkedTarget() const;
1030 
1036  static bool createSymbolicLink (const File& linkFileToCreate,
1037  const String& nativePathOfTarget,
1038  bool overwriteExisting);
1039 
1043 
1044  #if JUCE_WINDOWS || DOXYGEN
1046  bool createShortcut (const String& description, const File& linkFileToCreate) const;
1047 
1049  bool isShortcut() const;
1050  #else
1051 
1052  #endif
1053 
1054  //==============================================================================
1055  #if JUCE_MAC || JUCE_IOS || DOXYGEN
1057  OSType getMacOSType() const;
1058 
1060  bool isBundle() const;
1061  #endif
1062 
1063  #if JUCE_MAC || DOXYGEN
1065  void addToDock() const;
1066  #endif
1067 
1068  //==============================================================================
1071  {
1072  NaturalFileComparator (bool shouldPutFoldersFirst) noexcept : foldersFirst (shouldPutFoldersFirst) {}
1073 
1074  int compareElements (const File& firstFile, const File& secondFile) const
1075  {
1076  if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory()))
1077  return firstFile.isDirectory() ? -1 : 1;
1078 
1079  #if NAMES_ARE_CASE_SENSITIVE
1080  return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), true);
1081  #else
1082  return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), false);
1083  #endif
1084  }
1085 
1086  bool foldersFirst;
1087  };
1088 
1089  /* These static objects are deprecated because it's too easy to accidentally use them indirectly
1090  during a static constructor, which leads to very obscure order-of-initialisation bugs.
1091  Use File::getSeparatorChar() and File::getSeparatorString(), and instead of File::nonexistent,
1092  just use File() or {}.
1093  */
1094  JUCE_DEPRECATED_STATIC (static const juce_wchar separator;)
1095  JUCE_DEPRECATED_STATIC (static const StringRef separatorString;)
1096  JUCE_DEPRECATED_STATIC (static const File nonexistent;)
1097 
1098 private:
1099  //==============================================================================
1100  String fullPath;
1101 
1102  static String parseAbsolutePath (const String&);
1103  String getPathUpToLastSlash() const;
1104 
1105  Result createDirectoryInternal (const String&) const;
1106  bool copyInternal (const File&) const;
1107  bool moveInternal (const File&) const;
1108  bool replaceInternal (const File&) const;
1109  bool setFileTimesInternal (int64 m, int64 a, int64 c) const;
1110  void getFileTimesInternal (int64& m, int64& a, int64& c) const;
1111  bool setFileReadOnlyInternal (bool) const;
1112  bool setFileExecutableInternal (bool) const;
1113 };
1114 
1115 } // namespace juce
int getVolumeSerialNumber() const
bool isSymbolicLink() const
bool isHidden() const
bool isOnHardDisk() const
bool isDirectory() const
static void findFileSystemRoots(Array< File > &results)
bool setAsCurrentWorkingDirectory() const
bool isOnCDRomDrive() const
bool isOnRemovableDrive() const
int64 getVolumeTotalSize() const
int64 getBytesFreeOnVolume() const
const String & getFullPathName() const noexcept
Definition: juce_File.h:149
bool hasWriteAccess() const
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
~File()=default
void revealToUser() const
SpecialLocationType
Definition: juce_File.h:830
@ userMoviesDirectory
Definition: juce_File.h:847
@ userMusicDirectory
Definition: juce_File.h:844
@ tempDirectory
Definition: juce_File.h:882
@ globalApplicationsDirectory
Definition: juce_File.h:926
@ userDocumentsDirectory
Definition: juce_File.h:838
@ currentApplicationFile
Definition: juce_File.h:905
@ invokedExecutableFile
Definition: juce_File.h:912
@ commonDocumentsDirectory
Definition: juce_File.h:877
@ userApplicationDataDirectory
Definition: juce_File.h:858
@ userPicturesDirectory
Definition: juce_File.h:850
@ commonApplicationDataDirectory
Definition: juce_File.h:870
@ userDesktopDirectory
Definition: juce_File.h:841
@ hostApplicationPath
Definition: juce_File.h:915
@ currentExecutableFile
Definition: juce_File.h:895
@ userHomeDirectory
Definition: juce_File.h:832
static juce_wchar getSeparatorChar()
bool moveToTrash() const
String getVolumeLabel() const
uint64 getFileIdentifier() const
File()=default
bool deleteFile() const
String getVersion() const
String getNativeLinkedTarget() const
static File getCurrentWorkingDirectory()
static StringRef getSeparatorString()
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept