{"id":1856,"date":"2018-09-02T21:32:25","date_gmt":"2018-09-02T12:32:25","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=1856"},"modified":"2018-09-02T21:32:25","modified_gmt":"2018-09-02T12:32:25","slug":"%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%84%e3%83%87%e3%82%a3%e3%83%ac%e3%82%af%e3%83%88%e3%83%aa%e3%81%ae%e5%ad%98%e5%9c%a8%e3%83%81%e3%82%a7%e3%83%83%e3%82%af","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/1856","title":{"rendered":"\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af"},"content":{"rendered":"<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5165\u51fa\u529b\u3067\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6271\u3046\u969b\u3001\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u306f\u6b20\u304b\u305b\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u305d\u306e\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>os.path\u3092\u4f7f\u3046\u65b9\u6cd5<\/h2>\n<p>Python3\u3067\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u306e\u65b9\u6cd5\u306f\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u304c\u3001os.path\u30e2\u30b8\u30e5\u30fc\u30eb\u306eexists\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u304c\u4e00\u822c\u7684\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom os import path\r\npath.exists(&quot;.\/sample_file.txt&quot;) # \u30d1\u30b9\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\r\n<\/pre>\n<p>&nbsp;<br \/>\n\u307e\u305f\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u306e\u304b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u5b58\u5728\u3059\u308b\u306e\u304b\u3092\u5224\u5225\u3059\u308b\u5834\u5408\u306fisfile()\u3001isdir()\u304c\u4f7f\u3048\u307e\u3059\u3002\uff08\u30d5\u30a1\u30a4\u30eb\u304b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304b\u306e\u5224\u5b9a\u306b\u3082\u4f7f\u3048\u307e\u3059\u3002\uff09\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u306e\u5b58\u5728\u78ba\u8a8d\u3092\u3059\u308b\u5834\u5408\u306fislink()\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom os import path\r\npath.isfile(&quot;.\/sample_file.txt&quot;) # \u30d5\u30a1\u30a4\u30eb(\u5b58\u5728)\u5224\u5b9a\r\npath.isdir(&quot;.\/sample_file.txt&quot;) # \u30c7\u30a3\u30ec\u30af\u30c8\u30ea(\u5b58\u5728)\u5224\u5b9a\r\npath.islink(&quot;.\/sample_file.txt&quot;) # \u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af(\u5b58\u5728)\u5224\u5b9a\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2>pathlib.Path\u3092\u4f7f\u3046\u65b9\u6cd5<\/h2>\n<p>Python3.4\u4ee5\u964d\u3067\u306fpathlib.Path\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u65b9\u6cd5\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport pathlib\r\n\r\n# path\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\r\nfile_path = pathlib.Path(&quot;.\/sample_file.txt&quot;)\r\n\r\n# \u30d1\u30b9\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\r\nfile_path.exists()\r\n\r\n<\/pre>\n<p>&nbsp;<br \/>\npathlib.Path\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u8fd4\u3055\u308c\u308bPath\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u306e\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u30d1\u30b9\u3067\u3001os.path\u3068\u540c\u3058\u304f\u30d1\u30b9\u306e\u5b58\u5728\u78ba\u8a8d\u4ee5\u5916\u306b\u3082\u30d5\u30a1\u30a4\u30eb\/\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5224\u5b9a\u3001\u5b58\u5728\u5224\u5b9a\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport pathlib\r\n\r\n# path\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\r\nfile_path = pathlib.Path(&quot;.\/sample_file.txt&quot;)\r\n\r\n# \u5404\u7a2e\u30c1\u30a7\u30c3\u30af\r\nfile_path.is_dir() # \u30d5\u30a1\u30a4\u30eb(\u5b58\u5728)\u5224\u5b9a\r\nfile_path.is_file() # \u30c7\u30a3\u30ec\u30af\u30c8\u30ea(\u5b58\u5728)\u5224\u5b9a\r\nfile_path.is_symlink() # \u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af(\u5b58\u5728)\u5224\u5b9a\r\n\r\n<\/pre>\n<p>\u307e\u305f\u3001os.path\u3088\u308a\u6a5f\u80fd\u304c\u5f37\u5316\u3055\u308c\u3066\u304a\u308a\u3001\u4f8b\u3048\u3070Unix\u30c9\u30e1\u30a4\u30f3\u30bd\u30b1\u30c3\u30c8\u306e\u5224\u5b9a\u7b49\u3092\u884c\u3046\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfile_path.is_socket() # \u30bd\u30b1\u30c3\u30c8(\u5b58\u5728)\u5224\u5b9a\r\nfile_path.is_block_device() # \u30d6\u30ed\u30c3\u30af\u30c7\u30d0\u30a4\u30b9(\u5b58\u5728)\u5224\u5b9a\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5165\u51fa\u529b\u3067\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6271\u3046\u969b\u3001\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u306f\u6b20\u304b\u305b\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u305d\u306e\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 os.path\u3092\u4f7f\u3046\u65b9\u6cd5 Python3\u3067\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u306e\u65b9\u6cd5\u306f...<\/p>\n","protected":false},"author":1,"featured_media":1863,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1856"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=1856"}],"version-history":[{"count":20,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1856\/revisions"}],"predecessor-version":[{"id":1877,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1856\/revisions\/1877"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/1863"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=1856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=1856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=1856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}