{"id":5301,"date":"2022-04-02T19:05:36","date_gmt":"2022-04-02T11:05:36","guid":{"rendered":"https:\/\/egonlin.com\/?p=5301"},"modified":"2022-04-26T14:25:19","modified_gmt":"2022-04-26T06:25:19","slug":"08-04-os%e5%ba%93%e7%9a%84%e5%9f%ba%e6%9c%ac%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=5301","title":{"rendered":"08-04 os\u5e93\u7684\u57fa\u672c\u4f7f\u7528"},"content":{"rendered":"<h1>\u4e00\u3001os\u5e93\u57fa\u672c\u4ecb\u7ecd<\/h1>\n<p>os\u5e93\u63d0\u4f9b\u901a\u7528\u7684\u3001\u57fa\u672c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u529f\u80fd<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/os\u5e93\u7684\u57fa\u672c\u4f7f\u75281.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/os\u5e93\u7684\u57fa\u672c\u4f7f\u75281.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<ul>\n<li>os\u5e93\u662fPython\u6807\u51c6\u5e93\uff0c\u5305\u542b\u51e0\u767e\u4e2a\u51fd\u6570<\/li>\n<li>\u5e38\u7528\u8def\u5f84\u64cd\u4f5c\u3001\u8fdb\u7a0b\u7ba1\u7406\u3001\u73af\u5883\u53c2\u6570\u7b49\u51e0\u7c7b<\/li>\n<li>\u8def\u5f84\u64cd\u4f5c\uff1aos.path\u5b50\u5e93\uff0c\u5904\u7406\u6587\u4ef6\u8def\u5f84\u53ca\u4fe1\u606f<\/li>\n<li>\u8fdb\u7a0b\u7ba1\u7406\uff1a\u542f\u52a8\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7a0b\u5e8f<\/li>\n<li>\u73af\u5883\u53c2\u6570\uff1a\u83b7\u5f97\u7cfb\u7edf\u8f6f\u786c\u4ef6\u4fe1\u606f\u7b49\u73af\u5883\u53c2\u6570<\/li>\n<\/ul>\n<h1>\u4e8c\u3001os\u5e93\u4e4b\u8def\u5f84\u64cd\u4f5c<\/h1>\n<h2>2.1 \u8def\u5f84\u64cd\u4f5c<\/h2>\n<p>os.path\u5b50\u5e93\u4ee5path\u4e3a\u5165\u53e3\uff0c\u7528\u4e8e\u64cd\u4f5c\u548c\u5904\u7406\u6587\u4ef6\u8def\u5f84<\/p>\n<pre><code>import os.path`\u6216`import os.path as op<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u51fd\u6570<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">os.path.abspath(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56depath\u5728\u5f53\u524d\u7cfb\u7edf\u4e2d\u7684\u7edd\u5bf9\u8def\u5f84\uff0c<code>os.path.abspath(&quot;file.txt&quot;) # &#039;C:\\\\Users\\\\Tian Song\\\\Python36-32\\\\file.txt&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.normpath(path)<\/td>\n<td style=\"text-align: center;\">\u5f52\u4e00\u5316path\u7684\u8868\u793a\u5f62\u5f0f\uff0c\u7edf\u4e00\u7528\\\u5206\u9694\u8def\u5f84\uff0c<code>os.path.normpath(&quot;D:\/\/PYE\/\/file.txt&quot;) # &#039;D:\\\\PYE\\\\file.txt&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.relpath(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u5f53\u524d\u7a0b\u5e8f\u4e0e\u6587\u4ef6\u4e4b\u95f4\u7684\u76f8\u5bf9\u8def\u5f84 (relative path)\uff0c<code>os.path.relpath(&quot;C:\/\/PYE\/\/file.txt&quot;) # &#039;..\\\\..\\\\..\\\\..\\\\..\\\\..\\\\..\\\\PYE\\\\file.txt&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.dirname(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56depath\u4e2d\u7684\u76ee\u5f55\u540d\u79f0\uff0c<code>os.path.dirname(&quot;D:\/\/PYE\/\/file.txt&quot;) # &#039;D:\/\/PYE&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.basename(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56depath\u4e2d\u6700\u540e\u7684\u6587\u4ef6\u540d\u79f0\uff0c<code>os.path.basename(&quot;D:\/\/PYE\/\/file.txt&quot;) # &#039;file.txt&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.join(path, *paths)<\/td>\n<td style=\"text-align: center;\">\u7ec4\u5408path\u4e0epaths\uff0c\u8fd4\u56de\u4e00\u4e2a\u8def\u5f84\u5b57\u7b26\u4e32\uff0c<code>os.path.join(&quot;D:\/&quot;, &quot;PYE\/file.txt&quot;) # &#039;D:\/PYE\/file.txt&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.exists(path)<\/td>\n<td style=\"text-align: center;\">\u5224\u65adpath\u5bf9\u5e94\u6587\u4ef6\u6216\u76ee\u5f55\u662f\u5426\u5b58\u5728\uff0c\u8fd4\u56deTrue\u6216False\uff0c<code>os.path.exists(&quot;D:\/\/PYE\/\/file.txt&quot;) # False<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.isfile(path)<\/td>\n<td style=\"text-align: center;\">\u5224\u65adpath\u6240\u5bf9\u5e94\u662f\u5426\u4e3a\u5df2\u5b58\u5728\u7684\u6587\u4ef6\uff0c\u8fd4\u56deTrue\u6216False\uff0c<code>os.path.isfile(&quot;D:\/\/PYE\/\/file.txt&quot;) # True<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.isdir(path)<\/td>\n<td style=\"text-align: center;\">\u5224\u65adpath\u6240\u5bf9\u5e94\u662f\u5426\u4e3a\u5df2\u5b58\u5728\u7684\u76ee\u5f55\uff0c\u8fd4\u56deTrue\u6216False\uff0c<code>os.path.isdir(&quot;D:\/\/PYE\/\/file.txt&quot;) # False<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.getatime(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56depath\u5bf9\u5e94\u6587\u4ef6\u6216\u76ee\u5f55\u4e0a\u4e00\u6b21\u7684\u8bbf\u95ee\u65f6\u95f4\uff0c<code>os.path.getatime(&quot;D:\/PYE\/file.txt&quot;) # 1518356633.7551725<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.getmtime(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56depath\u5bf9\u5e94\u6587\u4ef6\u6216\u76ee\u5f55\u6700\u8fd1\u4e00\u6b21\u7684\u4fee\u6539\u65f6\u95f4\uff0c<code>os.path.getmtime(&quot;D:\/PYE\/file.txt&quot;) # 1518356633.7551725<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.getctime(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56depath\u5bf9\u5e94\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u521b\u5efa\u65f6\u95f4\uff0c<code>time.ctime(os.path.getctime(&quot;D:\/PYE\/file.txt&quot;)) # &#039;Sun Feb 11 21:43:53 2018&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">os.path.getsize(path)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56depath\u5bf9\u5e94\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\uff0c<code>os.path.getsize(&quot;D:\/PYE\/file.txt&quot;) # 180768<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-python\">os.path.abspath(path) \nos.path.normpath(path)\nos.path.relpath(path)\nos.path.dirname(path) \nos.path.basename(path)\nos.path.join(path)\nos.path.exists(path) \nos.path.isfile(path)\nos.path.isdir(path)\nos.path.getatime(path) \nos.path.getmtime(path)\nos.path.getctime(path)\nos.path.getsize(path)<\/code><\/pre>\n<h1>\u4e09\u3001os\u5e93\u4e4b\u8fdb\u7a0b\u7ba1\u7406<\/h1>\n<div id=\"rml_readmorelogin_placeholder\" style=\"position:relative;\"><div id=\"rml_fade_content\" style=\"position: absolute;\r\ntop:-10em;\r\nwidth:100%;\r\nheight:10em;\r\nbackground: -webkit-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -moz-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -o-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -ms-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\"><\/div><div class=\"wpf-controller aru_rml_from_in_post\" style=\"background-color:#eeeeee;border:5px solid #cce6ff;\" id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><h2 id=\"Header\">\u67e5\u770b\u66f4\u591a<\/h2><div id=\"Message\"><p>\u8054\u7cfb\u7ba1\u7406\u5458\u5fae\u4fe1tutu19192010\uff0c\u6ce8\u518c\u8d26\u53f7<\/p>\n<\/div><div id=\"StatusBarHeader\"><\/div><form id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><input name=\"post_id\" value=\"5301\" type=\"hidden\"\/><input name=\"_init_callback\" value=\"InitLogin\" type=\"hidden\"\/><input name=\"post_id\" value=\"5301\" type=\"hidden\"\/><input name=\"rt_ype\" value=\"1\" type=\"hidden\"\/><input name=\"nonce\" value=\"31a93419bb\" type=\"hidden\"\/><input name=\"_wpnonce\" value=\"f48666364f\" type=\"hidden\"\/><input name=\"_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_proxy_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_view\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginView\" type=\"hidden\"\/><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\" width=\"400px\"><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Username:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"username\" value=\"\" type=\"text\"\/><\/td><\/tr><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Password:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"password\" value=\"\" type=\"password\"\/><\/td><\/tr><\/tbody><\/table><p class=\"wpf-table-placeholder submit\"><button class=\"wp_plugin_framework_ajax_button\" type=\"button\" style=\"background-color:#4D90FE;;color:#ffffff;;border:1px solid #3079ed;\" name=\"_event\" value=\"ButtonLogin\">Log in<\/button><\/p><\/td><td class=\"wpf-table-placeholder-input\"><\/td><\/tr><\/tbody><\/table><\/form><div id=\"ButtonStartRegister\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=register\">Register<\/a><\/div><div id=\"Link1\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=lostpassword\">Forgotten username or password?<\/a><\/div><div id=\"StatusBarFooter\"><\/div><\/div><\/div><div id=aru_remaining_content><\/div>","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001os\u5e93\u57fa\u672c\u4ecb\u7ecd os\u5e93\u63d0\u4f9b\u901a\u7528\u7684\u3001\u57fa\u672c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u529f\u80fd os\u5e93\u662fPython\u6807\u51c6\u5e93\uff0c\u5305\u542b\u51e0\u767e\u4e2a\u51fd\u6570 \u5e38\u7528 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5302,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[371,383],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5301"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5301"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5301\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/5302"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}