//---------------------------------------------------------------------------------------- nsresult nsFileSpec::MoveToDir(const nsFileSpec& inNewParentDirectory) //---------------------------------------------------------------------------------------- { // We can only copy into a directory, and (for now) can not copy entire directories nsresult result = NS_FILE_FAILURE; if (inNewParentDirectory.IsDirectory() && !IsDirectory()) { char *leafname = GetLeafName(); nsSimpleCharString destPath(inNewParentDirectory.GetCString()); destPath += "/"; destPath += leafname; nsCRT::free(leafname); result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), (const char*)destPath)); if (result == NS_OK) { // cast to fix const-ness ((nsFileSpec*)this)->Delete(PR_FALSE); *this = inNewParentDirectory + GetLeafName(); } } return result; }
//---------------------------------------------------------------------------------------- void nsFileURL::operator = (const nsFileSpec& inOther) //---------------------------------------------------------------------------------------- { *this = nsFilePath(inOther); if (mURL[mURL.Length() - 1] != '/' && inOther.IsDirectory()) mURL += "/"; } // nsFileURL::operator =
//---------------------------------------------------------------------------------------- nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const //---------------------------------------------------------------------------------------- { // We can only copy into a directory, and (for now) can not copy entire directories nsresult result = NS_FILE_FAILURE; if (inParentDirectory.IsDirectory() && (! IsDirectory() ) ) { char *leafname = GetLeafName(); nsSimpleCharString destPath(inParentDirectory.GetCString()); destPath += "/"; destPath += leafname; nsCRT::free(leafname); result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), destPath)); } return result; } // nsFileSpec::CopyToDir
//---------------------------------------------------------------------------------------- nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const //---------------------------------------------------------------------------------------- { // We can only copy into a directory, and (for now) can not copy entire directories if (inParentDirectory.IsDirectory() && (! IsDirectory() ) ) { char *leafname = GetLeafName(); nsSimpleCharString destPath(inParentDirectory.GetCString()); destPath += "\\"; destPath += leafname; nsCRT::free(leafname); // CopyFile returns non-zero if succeeds int copyOK = CopyFile(GetCString(), destPath, PR_TRUE); if (copyOK) return NS_OK; } return NS_FILE_FAILURE; } // nsFileSpec::CopyToDir