{"id":4437,"date":"2015-12-18T13:08:58","date_gmt":"2015-12-18T04:08:58","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=4437"},"modified":"2015-12-19T10:02:24","modified_gmt":"2015-12-19T01:02:24","slug":"funcdir","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/funcdir\/","title":{"rendered":"\u30d5\u30a1\u30a4\u30eb\u306e\u691c\u7d22\u30fb\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u3092\u53d6\u5f97\uff08Dir \u95a2\u6570\uff09"},"content":{"rendered":"<h2>Dir \u95a2\u6570<\/h2>\n<div class=\"m30-l\">\n<p><strong>Dir \u95a2\u6570<\/strong>\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u78ba\u8a8d\u3057\u305f\u308a\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u4e00\u89a7\u3092\u53d6\u5f97\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>string<\/em> = <strong>Dir<\/strong> ( [ <em>pathname<\/em> ,<em>atribute<\/em> ] )<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h3>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>string&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u30d1\u30b9\u3092\u9664\u3044\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u3002\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u7a7a\u6587\u5b57\uff08&#8221;&#8221;\uff09\u3002<\/li>\n<li>pathname&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u691c\u7d22\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3001\u30d5\u30a9\u30eb\u30c0\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u30d5\u30a9\u30eb\u30c0\u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u691c\u7d22\u5bfe\u8c61\u3068\u306a\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u8907\u6570\u306e\u6587\u5b57\u3092\u793a\u3059 * \u3084 1 \u6587\u5b57\u3092\u793a\u3059 ? \u3092\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u3068\u3057\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u521d\u56de\u547c\u3073\u51fa\u3057\u6642\u306b\u3001<em>pathname<\/em> \u3092\u7701\u7565\u3059\u308b\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002\uff12\u56de\u3081\u4ee5\u964d\u306f\u3001\u6700\u521d\u306b\u6307\u5b9a\u3057\u305f\u30d1\u30b9\u304c\u691c\u7d22\u5bfe\u8c61\u3068\u306a\u308a\u307e\u3059\u3002\u307e\u305f\u3001<strong>Dir(&#8220;&#8221;)<\/strong> \u3068\u3059\u308b\u3068\u30ab\u30ec\u30f3\u30c8\u30d5\u30a9\u30eb\u30c0\u304c\u691c\u7d22\u5bfe\u8c61\u3068\u306a\u308a\u307e\u3059\u3002<\/li>\n<li>atribute&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30d5\u30a1\u30a4\u30eb\u306e\u5c5e\u6027\u3092\u8868\u3059\u5b9a\u6570\u3001\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n<table>\n<tr>\n<td align = \"center\" width=\"200\" bgcolor=\"#ffffccc\"><strong>\u5b9a\u6570<\/strong><\/td>\n<td align = \"center\" width=\"50\" bgcolor=\"#ffffccc\"><strong>\u5024<\/strong><\/td>\n<td align = \"center\" width=\"400\" bgcolor=\"#ffffccc\"><strong>\u5185\u5bb9<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"200\">vbNormal<\/td>\n<td width=\"50\" align = \"center\">0<\/td>\n<td width=\"400\">(\u65e2\u5b9a\u5024) \u5c5e\u6027\u306e\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">vbReadOnly<\/td>\n<td width=\"50\" align = \"center\">1<\/td>\n<td width=\"400\">\u5c5e\u6027\u306e\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u3068\u8aad\u307f\u53d6\u308a\u5c02\u7528\u306e\u30d5\u30a1\u30a4\u30eb\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">vbHidden<\/td>\n<td width=\"50\" align = \"center\">2<\/td>\n<td width=\"400\">\u5c5e\u6027\u306e\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u3068\u96a0\u3057\u30d5\u30a1\u30a4\u30eb\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">VbSystem<\/td>\n<td width=\"50\" align = \"center\">4<\/td>\n<td width=\"400\">\u5c5e\u6027\u306e\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u3068\u30b7\u30b9\u30c6\u30e0 \u30d5\u30a1\u30a4\u30eb\u3002Macintosh \u3067\u306f\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">vbVolume<\/td>\n<td width=\"50\" align = \"center\">8<\/td>\n<td width=\"400\">\u30dc\u30ea\u30e5\u30fc\u30e0 \u30e9\u30d9\u30eb\u3002\u4ed6\u306e\u5c5e\u6027\u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u3001vbVolume \u306f\u7121\u8996\u3055\u308c\u307e\u3059\u3002Macintosh \u3067\u306f\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">vbDirectory<\/td>\n<td width=\"50\" align = \"center\">16<\/td>\n<td width=\"400\">\u5c5e\u6027\u306e\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u3068\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u307e\u305f\u306f\u30d5\u30a9\u30eb\u30c0\u30fc\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">vbAlias<\/td>\n<td width=\"50\" align = \"center\">64<\/td>\n<td width=\"400\">\u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u30a8\u30a4\u30ea\u30a2\u30b9\u3068\u3057\u3066\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u30d5\u30a1\u30a4\u30eb\u3002Macintosh \u3067\u306e\u307f\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<\/td>\n<\/tr>\n<\/table>\n<p>\n      <\/ul>\n<br \/>\n<p class=\"caution4\"><strong>Dir \u95a2\u6570<\/strong>\u306f\u3001\u691c\u7d22\u6761\u4ef6\u306b\u5408\u81f4\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u304c\u8907\u6570\u5b58\u5728\u3059\u308b\u5834\u5408\u3001\u6700\u521d\u306b\u898b\u3064\u304b\u3063\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u8fd4\u3057\u307e\u3059\u3002\u6b21\u306b\u3001\u5f15\u6570\u306a\u3057\u3067\u3001<strong>Dir \u95a2\u6570<\/strong> \u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u6b21\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8fd4\u3057\u307e\u3059\u3002\u3053\u308c\u3092\u7d9a\u3051\u308b\u3053\u3068\u3067\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p class=\"caution8\">Dir \u95a2\u6570\u3068\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u78ba\u8a8d\u3092\u78ba\u8a8d\u3059\u308b\u5834\u5408\u306e\u6ce8\u610f<br \/>\n\u3000\u3000<strong>Dir(*.xls)<\/strong><br \/>\n\u3068\u6307\u5b9a\u3059\u308b\u3068\u3001\u62e1\u5f35\u5b50\u300cxls\u300d\u3060\u3051\u3067\u306a\u304f\u300cxlsx\u300d\u3084\u300cxlsm\u300d\u306a\u3069\u300cxls\u300d\u3092\u542b\u3080\u62e1\u5f35\u5b50\u3059\u3079\u3066\u304c\u691c\u7d22\u6761\u4ef6\u306b\u4e00\u81f4\u3057\u3066\u3057\u307e\u3046\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<\/p><\/div>\n<\/div>\n<br \/><br \/>\n<h2>Dir \u95a2\u6570 \u4f7f\u7528\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9 1\uff08\u30d5\u30a1\u30a4\u30eb\u30fb\u30d5\u30a9\u30eb\u30c0\u306e\u691c\u7d22\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Dir \u95a2\u6570 \u4f7f\u7528\u4f8b 1\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample01_Dir()\r\n\r\n    Dim fname1, fname2\r\n    \r\n    fname1 = Dir(\"C:\\Documents\\mybook.xlsx\", vbNormal)\r\n    fname2 = Dir(\"C:\\Documents\\mybook0.xlsx\", vbNormal)\r\n    \r\n    If fname1 = \"\" Then fname1 = \"\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\"\r\n    If fname2 = \"\" Then fname2 = \"\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\"\r\n\r\n    MsgBox fname1 & vbCrLf & fname2\r\n\r\nEnd Sub\r\n\u3000\r\n    <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c 1<\/h3>\n<p><a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir01.jpg?ssl=1\" rel=\"lightbox[4437]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir01.jpg?resize=170%2C170&#038;ssl=1\" alt=\"Dir \u95a2\u6570 01\" width=\"170\" height=\"170\" class=\"alignnone size-full wp-image-4438\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir01.jpg?w=170&amp;ssl=1 170w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir01.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir01.jpg?resize=100%2C100&amp;ssl=1 100w\" sizes=\"(max-width: 170px) 100vw, 170px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9 2\uff08\u30d5\u30eb\u30d1\u30b9\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u53d6\u5f97\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Dir \u95a2\u6570 \u4f7f\u7528\u4f8b 2\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample02_Dir()\r\n    '\u30d5\u30a1\u30a4\u30eb\u540d\u30fb\u30d1\u30b9\u3092\u53d6\u5f97\u3059\u308b\r\n\r\n    Dim fullfile1, fullfile2\r\n    Dim fname1, fname2, dname1, dname2\r\n    \r\n    fullfile1 = \"C:\\Documents\\mybook.xlsx\"\r\n    fullfile2 = \"C:\\Documents\\mybook0.xlsx\"\r\n    \r\n    \r\n    '\u3010\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u3011\r\n    \r\n    '\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u307f\u3092\u53d6\u5f97\r\n    fname1 = Dir(fullfile1)\r\n    \r\n    '\u30d1\u30b9\u306e\u307f\u3092\u53d6\u5f97\uff08\u6700\u5f8c\u306b\u300c\\\u300d\u542b\u3080\uff09\r\n    dname1 = Replace(fullfile1, Dir(fullfile1), \"\")\r\n    \r\n    \r\n    \r\n    '\u3010\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u3001\u3057\u306a\u3044\u306b\u95a2\u4fc2\u306a\u304f\u4f7f\u7528\u3067\u304d\u308b\u3011\r\n    '\u203b FileSystemObject \u4f7f\u7528\r\n    \r\n    Dim fso\r\n    Set fso = CreateObject(\"Scripting.FileSystemObject\")\r\n    \r\n    '\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u307f\u3092\u53d6\u5f97\r\n    fname2 = fso.GetFilename(fullfile2)\r\n\r\n    '\u30d1\u30b9\u306e\u307f\u3092\u53d6\u5f97\uff08\u6700\u5f8c\u306b\u300c\\\u300d\u542b\u307e\u306a\u3044\uff09\r\n    dname2 = fso.GetParentFolderName(fullfile2)\r\n\r\n    Set fso = Nothing\r\n\r\n    '\u8868\u793a\r\n    MsgBox \"fname1:\" & fname1 & vbCrLf & \"dname1:\" & dname1 & vbCrLf & _\r\n           \"fname2:\" & fname2 & vbCrLf & \"dname2:\" & dname2\r\n    \r\nEnd Sub\r\n\u3000\r\n    <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c 2<\/h3>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir02.jpg?ssl=1\" rel=\"lightbox[4437]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir02.jpg?resize=210%2C200&#038;ssl=1\" alt=\"Dir \u95a2\u6570 02\" width=\"210\" height=\"200\" class=\"alignnone size-full wp-image-4439\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9 3\uff08\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u3092\u53d6\u5f97\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Dir \u95a2\u6570 \u4f7f\u7528\u4f8b 3\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample03_Dir()\r\n\r\n    Dim myFile As String, strFiles As String\r\n    \r\n    myFile = Dir(\"C:\\Documents\\*.xlsx\")\r\n    strFiles = myFile\r\n    \r\n    Do While myFile <> \"\"\r\n        \r\n        myFile = Dir()\r\n        strFiles = strFiles & vbCrLf & myFile\r\n    \r\n    Loop\r\n    \r\n    MsgBox strFiles\r\n\r\nEnd Sub\r\n\u3000\r\n    <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c 3<\/h3>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir03.jpg?ssl=1\" rel=\"lightbox[4437]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir03.jpg?resize=168%2C185&#038;ssl=1\" alt=\"Dir \u95a2\u6570 03\" width=\"168\" height=\"185\" class=\"alignnone size-full wp-image-4440\" data-recalc-dims=\"1\" \/><\/a><\/p><\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>Dir \u95a2\u6570 Dir \u95a2\u6570\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u78ba\u8a8d\u3057\u305f\u308a\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":4438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[675],"tags":[691,693,692,63,38],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/12\/func_dir01.jpg?fit=170%2C170&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s4Ye9i-funcdir","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/4437"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=4437"}],"version-history":[{"count":7,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/4437\/revisions"}],"predecessor-version":[{"id":4609,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/4437\/revisions\/4609"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/4438"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=4437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=4437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=4437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}