@@ -216,30 +216,53 @@ namespace libim {
216
216
return svpext == ext;
217
217
}
218
218
219
- inline bool isFilePath (const std::string & path)
219
+ inline bool isFilePath (const std::filesystem::path & path, OptionalRef<std::error_code> ec = std::nullopt )
220
220
{
221
- return path.find_last_of (" ." ) != std::string::npos;
221
+ using namespace std ::filesystem;
222
+ if (ec) {
223
+ return is_regular_file (path, *ec) || path.has_extension ();
224
+ }
225
+ return is_regular_file (path) || path.has_extension ();
226
+ }
227
+
228
+ inline bool isFilePath (const std::string& path, OptionalRef<std::error_code> ec)
229
+ {
230
+ return isFilePath (std::filesystem::path (path), ec);
222
231
}
223
232
224
233
inline bool fileExists (const std::filesystem::path& filePath)
225
234
{
226
- if (filePath.empty ()) {
235
+ if (filePath.empty () || ! isFilePath (filePath) ) {
227
236
return false ;
228
237
}
229
238
230
239
return std::filesystem::exists (filePath);
231
240
}
232
241
242
+ inline bool isDirPath (const std::filesystem::path& path, OptionalRef<std::error_code> ec = std::nullopt)
243
+ {
244
+ using namespace std ::filesystem;
245
+ if (ec) {
246
+ return is_directory (path, *ec) || !isFilePath (path);
247
+ }
248
+ return is_directory (path) || !isFilePath (path);
249
+ }
250
+
251
+ inline bool isDirPath (const std::string& path, OptionalRef<std::error_code> ec)
252
+ {
253
+ return isDirPath (std::filesystem::path (path), ec);
254
+ }
255
+
233
256
inline bool dirExists (const std::filesystem::path& dirPath)
234
257
{
235
- if (dirPath.empty ()) {
258
+ if (dirPath.empty () || isFilePath (dirPath) ) {
236
259
return false ;
237
260
}
238
261
else if (!isNativePath (dirPath.string ())) {
239
262
return dirExists (getNativePath (dirPath.string ()));
240
263
}
241
264
242
- return std::filesystem::exists (dirPath);
265
+ return std::filesystem::exists (dirPath);
243
266
}
244
267
245
268
inline bool makeDir (const std::filesystem::path& dirName)
@@ -298,7 +321,7 @@ namespace libim {
298
321
return removeFile (file, ec);
299
322
}
300
323
301
- inline bool renameFile (const std::filesystem::path& from, const std::filesystem::path&& to, bool override = true )
324
+ inline bool renameFile (const std::filesystem::path& from, const std::filesystem::path& to, bool override = true )
302
325
{
303
326
if (fileExists (to) && !override ) {
304
327
return false ;
0 commit comments