--- a/src/megacmdexecuter.cpp
+++ b/src/megacmdexecuter.cpp
@@ -1919,7 +1919,7 @@ bool MegaCmdExecuter::TestCanWriteOnContainingFolder(string *path)
     if (index)
     {
         // Remove the current leaf name.
-        containingFolder.truncate(index);
+        containingFolder = containingFolder.parentPath();
     }
     else
     {
