MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / rename

Method rename

src/openms/source/SYSTEM/File.cpp:157–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155 }
156
157 bool File::rename(const String& from, const String& to, bool overwrite_existing, bool verbose)
158 {
159 // check for equality
160 if (QFileInfo(from.c_str()).canonicalFilePath() == QFileInfo(to.c_str()).canonicalFilePath())
161 { // same file; no need to to anything
162 return true;
163 }
164
165 // existing file? Qt won't overwrite, so try to remove it:
166 if (overwrite_existing && exists(to) && !remove(to))
167 {
168 if (verbose)
169 {
170 OPENMS_LOG_ERROR << "Error: Could not overwrite existing file '" << to << "'\n";
171 }
172 return false;
173 }
174 // move the file to the actual destination:
175 if (!QFile::rename(from.toQString(), to.toQString()))
176 {
177 if (verbose)
178 {
179 OPENMS_LOG_ERROR << "Error: Could not move '" << from << "' to '" << to << "'\n";
180 }
181 return false;
182 }
183 return true;
184 }
185
186 // https://stackoverflow.com/questions/2536524/copy-directory-using-qt
187 bool File::copyDirRecursively(const QString& from_dir, const QString& to_dir, File::CopyOptions option)

Callers 1

renameOutput_Method · 0.80

Calls 1

toQStringMethod · 0.45

Tested by

no test coverage detected