15namespace fs = std::filesystem;
18 fs::path ToFsPath(
const DotNetDupe::System::String& sPath) {
26 std::regex PatternToRegex(
const DotNetDupe::System::String& sPattern) {
28 std::string sRegexStr;
30 if (c ==
'*') sRegexStr +=
".*";
31 else if (c ==
'?') sRegexStr +=
".";
32 else if (c ==
'.' || c ==
'\\' || c ==
'/' || c ==
'(' || c ==
')' || c ==
'[' || c ==
']' || c ==
'^' || c ==
'$' || c ==
'+' || c ==
'|' || c ==
'{' || c ==
'}') {
39 return std::regex(
"^" + sRegexStr +
"$", std::regex_constants::icase);
42 DotNetDupe::System::DateTimeOffset FileTimeToDateTimeOffset(fs::file_time_type ftime) {
43 auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
44 ftime - fs::file_time_type::clock::now() + std::chrono::system_clock::now()
46 auto durationSec = std::chrono::duration_cast<std::chrono::seconds>(sctp.time_since_epoch()).count();
48 int64_t ticks = (durationSec + 62135596800LL) * 10000000LL;
49 return DotNetDupe::System::DateTimeOffset(ticks);
58 if (sPath.
IsEmpty())
return false;
61 return fs::is_directory(ToFsPath(sPath), ec);
77 fs::create_directories(ToFsPath(sPath), ec);
79 fs::create_directory(ToFsPath(sPath), ec);
96 fs::path p = ToFsPath(sPath);
98 if (!fs::exists(p, ec)) {
104 fs::remove_all(p, ec);
120 fs::rename(ToFsPath(sSourceDirName), ToFsPath(sDestDirName), ec);
136 std::vector<String> results;
137 std::regex reg = PatternToRegex(sSearchPattern);
141 for (
const auto& entry : fs::directory_iterator(ToFsPath(sPath), ec)) {
142 if (entry.is_regular_file(ec)) {
143 std::string filename = entry.path().filename().string();
144 if (std::regex_match(filename, reg)) {
145 results.push_back(
String(entry.path().string().c_str()));
151 for (
int iIdx = 0; iIdx < (int)results.size(); iIdx++) arr[iIdx] = results[iIdx];
165 std::vector<String> results;
166 std::regex reg = PatternToRegex(sSearchPattern);
170 for (
const auto& entry : fs::directory_iterator(ToFsPath(sPath), ec)) {
171 if (entry.is_directory(ec)) {
172 std::string filename = entry.path().filename().string();
173 if (std::regex_match(filename, reg)) {
174 results.push_back(
String(entry.path().string().c_str()));
180 for (
int iIdx = 0; iIdx < (int)results.size(); iIdx++) arr[iIdx] = results[iIdx];
194 std::vector<String> results;
195 std::regex reg = PatternToRegex(sSearchPattern);
199 for (
const auto& entry : fs::directory_iterator(ToFsPath(sPath), ec)) {
200 std::string filename = entry.path().filename().string();
201 if (std::regex_match(filename, reg)) {
202 results.push_back(
String(entry.path().string().c_str()));
207 for (
int iIdx = 0; iIdx < (int)results.size(); iIdx++) arr[iIdx] = results[iIdx];
214 fs::path p = fs::current_path(ec);
218 return String(p.string().c_str());
228 fs::current_path(ToFsPath(sPath), ec);
247 auto ftime = fs::last_write_time(ToFsPath(sPath), ec);
251 return FileTimeToDateTimeOffset(ftime);
Defines the exception thrown when an invalid argument is provided to a method.
The exception that is thrown when an I/O error occurs.
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
static void CreateDirectory(const String &sPath)
Creates all directories and subdirectories in the specified path unless they already exist.
static Array< String > GetDirectories(const String &sPath)
Returns the names of subdirectories (including their paths) in the specified directory.
static DateTimeOffset GetCreationTime(const String &sPath)
Gets the creation date and time of a directory.
static void SetCurrentDirectory(const String &sPath)
Sets the application's current working directory to the specified directory.
static DateTimeOffset GetLastWriteTime(const String &sPath)
Returns the date and time the specified file or directory was last written to.
static void Delete(const String &sPath)
Deletes an empty directory from a specified path.
static String GetCurrentDirectory()
Gets the current working directory of the application.
static void Move(const String &sSourceDirName, const String &sDestDirName)
Moves a file or a directory and its contents to a new location.
static bool Exists(const String &sPath)
Determines whether the given path refers to an existing directory on disk.
static DateTimeOffset GetLastAccessTime(const String &sPath)
Returns the date and time the specified file or directory was last accessed.
static Array< String > GetFiles(const String &sPath)
Returns the names of files (including their paths) in the specified directory.
static Array< String > GetFileSystemEntries(const String &sPath)
Returns the names of all files and subdirectories in the specified directory.
static String GetDirectoryRoot(const String &sPath)
Returns the volume information, root information, or both for the specified path.
The exception that is thrown when an I/O error occurs.
static String GetPathRoot(const String &sPath)
Gets the root directory information from the path contained in the specified string.
static std::wstring Utf8ToWChar(const char *pUtf8Str)
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
String()
Initializes a new instance of the String class to an empty string.
const char * GetRawString() const