{"id":378,"date":"2015-06-12T09:59:23","date_gmt":"2015-06-12T01:59:23","guid":{"rendered":"http:\/\/gnonstop.linkpc.net\/~gordon\/?p=378"},"modified":"2025-08-22T22:05:38","modified_gmt":"2025-08-22T14:05:38","slug":"check-string-as-valid-filename","status":"publish","type":"post","link":"https:\/\/guerilla.ddns.net\/wp\/?p=378","title":{"rendered":"check string as valid filename"},"content":{"rendered":"<pre><code class=\"language-cpp\" data-line=\"\">    bool ContainsInvalidChars(const CString&amp; filename)\n    {\n        const TCHAR invalidChars[] = { &#039;&lt;&#039;, &#039;&gt;&#039;, &#039;:&#039;, &#039;&quot;&#039;, &#039;\/&#039;, &#039;\\\\&#039;, &#039;|&#039;, &#039;?&#039;, &#039;*&#039; };\n        for (int i = 0; i &lt; _countof(invalidChars); ++i)\n        {\n            if (filename.Find(invalidChars[i]) != -1)\n            {\n                return true;\n            }\n        }\n        return false;\n    }<\/code><\/pre>\n<p>&nbsp;<br \/>\nor<\/p>\n<pre><code class=\"language-cpp\" data-line=\"\">\n    bool isValidFilenameSyntax(const std::string&amp; filename)\n    {\n        if (filename.empty()) {\n            return false;\n        }\n\n        \/\/ Common invalid characters for Windows (adjust for other OS if needed)\n        const std::string invalidChars = &quot;\\\\\/:*?\\&quot;&lt;&gt;|&quot;; \n        for (char c : filename) {\n            if (invalidChars.find(c) != std::string::npos) {\n                return false;\n            }\n        }\n\n        \/\/ Add checks for reserved names, length limits, etc. if required\n        \/\/ For example, on Windows, check for CON, PRN, AUX, NUL\n        \/\/ if (filename == &quot;CON&quot; || filename == &quot;PRN&quot; || ...) { return false; }\n\n        return true;\n    }<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<br \/>\n#cpp<\/p>\n","protected":false},"excerpt":{"rendered":"<p>bool ContainsInvalidChars(const CString&amp; filename)  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[212],"tags":[85,27],"class_list":["post-378","post","type-post","status-publish","format-standard","hentry","category-coding","tag-c","tag-coding"],"_links":{"self":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=378"}],"version-history":[{"count":6,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":3419,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions\/3419"}],"wp:attachment":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}