]> git.saurik.com Git - wxWidgets.git/commitdiff
added overwrite parameter to wxRenameFile (patch 1467041)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 16 Apr 2006 21:14:00 +0000 (21:14 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 16 Apr 2006 21:14:00 +0000 (21:14 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/function.tex
include/wx/filefn.h
src/common/filefn.cpp

index 7addfe5654ee8e9ae216ab4072c41ea77bc53b10..0164792561624662b298d8354dc2e9063b172b40 100644 (file)
@@ -1215,10 +1215,14 @@ Removes \arg{file}, returning true if successful.
 
 \membersection{::wxRenameFile}\label{wxrenamefile}
 
-\func{bool}{wxRenameFile}{\param{const wxString\& }{file1}, \param{const wxString\& }{file2}}
+\func{bool}{wxRenameFile}{\param{const wxString\& }{file1}, \param{const wxString\& }{file2}, \param{bool overwrite = true}}
 
 Renames \arg{file1} to \arg{file2}, returning true if successful.
 
+If \arg{overwrite} parameter is true (default), the destination file is
+overwritten if it exists, but if \arg{overwrite} is false, the functions fails
+in this case.
+
 
 \membersection{::wxRmdir}\label{wxrmdir}
 
index 4189de1bf108966cff69854f5d41db45f39b9f10..3351115ba7014cb151b9d6fb31be7aeeeb70c2e6 100644 (file)
@@ -436,7 +436,7 @@ WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
 WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
 
 // Rename file
-WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2);
+WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
 
 // Get current working directory.
 #if WXWIN_COMPATIBILITY_2_6
index 5168a4cff508cfba6f64fd00f5d5d2e472a3a8e6..4bf2c7cdd506b9ebfc7881bd88bd48b6203066cb 100644 (file)
@@ -1106,8 +1106,19 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite)
 }
 
 bool
-wxRenameFile (const wxString& file1, const wxString& file2)
+wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite)
 {
+    if ( !overwrite && wxFileExists(file2) )
+    {
+        wxLogSysError
+        (
+            _("Failed to rename the file '%s' to '%s' because the destination file already exists."),
+            file1.c_str(), file2.c_str()
+        );
+
+        return false;
+    }
+
 #if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
     // Normal system call
   if ( wxRename (file1, file2) == 0 )
@@ -1115,7 +1126,7 @@ wxRenameFile (const wxString& file1, const wxString& file2)
 #endif
 
   // Try to copy
-  if (wxCopyFile(file1, file2)) {
+  if (wxCopyFile(file1, file2, overwrite)) {
     wxRemoveFile(file1);
     return true;
   }