diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index 486c61d3b2..ae90773e27 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -360,6 +360,14 @@ File File::getParentDirectory() const return createFileWithoutCheckingPath (getPathUpToLastSlash()); } +bool File::isNonEmptyDirectory() const +{ + if (! isDirectory()) + return false; + + return RangedDirectoryIterator (*this, false, "*", findFilesAndDirectories) != RangedDirectoryIterator(); +} + //============================================================================== String File::getFileName() const { diff --git a/modules/juce_core/files/juce_File.h b/modules/juce_core/files/juce_File.h index e24dc74909..1d62a888da 100644 --- a/modules/juce_core/files/juce_File.h +++ b/modules/juce_core/files/juce_File.h @@ -510,6 +510,10 @@ public: Also note that on some OSes (e.g. Windows), moving files between different volumes may not be possible. + This function will often fail to move directories because of the ambiguities + about merging existing directories. Use copyDirectoryTo() and deleteRecursively() + in these situations. + @returns true if the operation succeeds */ bool moveFileTo (const File& targetLocation) const; @@ -1150,6 +1154,7 @@ private: static String parseAbsolutePath (const String&); String getPathUpToLastSlash() const; + bool isNonEmptyDirectory() const; Result createDirectoryInternal (const String&) const; bool copyInternal (const File&) const; diff --git a/modules/juce_core/native/juce_SharedCode_posix.h b/modules/juce_core/native/juce_SharedCode_posix.h index 03313eaa27..0ca2feb205 100644 --- a/modules/juce_core/native/juce_SharedCode_posix.h +++ b/modules/juce_core/native/juce_SharedCode_posix.h @@ -405,6 +405,9 @@ bool File::moveInternal (const File& dest) const if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0) return true; + if (isNonEmptyDirectory()) + return false; + if (hasWriteAccess() && copyInternal (dest)) { if (deleteFile())