{"id":5259,"date":"2016-03-23T20:42:32","date_gmt":"2016-03-23T11:42:32","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=5259"},"modified":"2016-12-10T08:31:18","modified_gmt":"2016-12-09T23:31:18","slug":"filesystemobject","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/filesystemobject\/","title":{"rendered":"\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08FileSystemObject\uff09\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"<h2>\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08FileSystemObject\uff09<\/h2>\n<div class=\"m30-l\">\n<p><strong>FileSystemObject\uff08FSO\uff09<\/strong>\u3092\u5229\u7528\u3059\u308b\u3068<strong>\u30d5\u30a1\u30a4\u30eb<\/strong>\u3001<strong>\u30d5\u30a9\u30eb\u30c0<\/strong>\u3001<strong>\u30c9\u30e9\u30a4\u30d6<\/strong>\u306e\u69d8\u3005\u306a\u64cd\u4f5c\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n    <strong>FileSystemObject\uff08FSO\uff09<\/strong>\u3092\u5229\u7528\u3059\u308b\u306b\u306f\u3001<strong>Microsoft Scripting Runtime<\/strong> \u3092\u53c2\u7167\u8a2d\u5b9a\u3059\u308b\u304b\u3001<strong>CreateObject \u95a2\u6570<\/strong> \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n    \u306a\u304a\u3001FileSystemObject \u306e\u5834\u5408\u3001\u4f7f\u7528\u5f8c\u306e\u89e3\u653e\uff08 Set FSO = Nothing \u3068\u304b\uff09\u306f\u4e0d\u8981\u306e\u3088\u3046\u3067\u3059\uff08\u305f\u3076\u3093\uff09\u3002\u3064\u3051\u3066\u3044\u308b\u65b9\u3082\u3044\u3089\u3063\u3057\u3083\u308b\u306e\u3067\u3001\u6c17\u306b\u306a\u308b\u65b9\u306f\u3064\u3051\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<br \/>\n<h3>FileSystemObject\uff08FSO\uff09\u3092\u5229\u7528\u3059\u308b\uff11<\/h3>\n<p><strong>Microsoft Scripting Runtime<\/strong> \u3092\u53c2\u7167\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<ol style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li><strong>VBE\uff08Visual Basic Editor\uff09<\/strong> \u3092\u8d77\u52d5\u3057\u3001[\u30c4\u30fc\u30eb] &#8211; [\u53c2\u7167\u8a2d\u5b9a] \u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings01.jpg?ssl=1\" rel=\"lightbox[5259]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings01.jpg?resize=580%2C396&#038;ssl=1\" alt=\"FSO \u53c2\u7167\u8a2d\u5b9a 1\" width=\"580\" height=\"396\" class=\"alignnone size-large wp-image-5264\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings01.jpg?resize=580%2C396&amp;ssl=1 580w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings01.jpg?resize=400%2C273&amp;ssl=1 400w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings01.jpg?resize=768%2C524&amp;ssl=1 768w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings01.jpg?w=953&amp;ssl=1 953w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a>\n    <\/li>\n<li>\u300c\u53c2\u7167\u8a2d\u5b9a\u300d\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3001\u30b9\u30af\u30ed\u30fc\u30eb\u30d0\u30fc\u3092\u52d5\u304b\u3057\u3001\u300cMicrosoft Scripting Runtime\u300d\u3092\u8868\u793a\u3057\u3001\u30c1\u30a7\u30c3\u30af\u30de\u30fc\u30af\u3092\u4ed8\u3051\u3066\u3001\u300cOK\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings03.jpg?ssl=1\" rel=\"lightbox[5259]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings03.jpg?resize=469%2C324&#038;ssl=1\" alt=\"FSO \u53c2\u7167\u8a2d\u5b9a 2\" width=\"469\" height=\"324\" class=\"alignnone size-full wp-image-5266\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings03.jpg?w=469&amp;ssl=1 469w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings03.jpg?resize=400%2C276&amp;ssl=1 400w\" sizes=\"(max-width: 469px) 100vw, 469px\" data-recalc-dims=\"1\" \/><\/a>\n    <\/li>\n<\/ol>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <span class=\"red\"><strong>\uff1cFileSystemObject \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\uff1e<\/strong><\/span><br \/>\n    <strong>Dim<\/strong> <em>fso<\/em> <strong>As New FileSystemObject<\/strong><\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>fso&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u4efb\u610f\u306e\u540d\u524d\uff08 <strong>FileSystemObject \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong> \u306e\u5909\u6570\u540d\uff09\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<br \/><\/div>\n<br \/><br \/>\n<h3>FileSystemObject\uff08FSO\uff09\u3092\u5229\u7528\u3059\u308b\uff12<\/h3>\n<p>\u53c2\u7167\u8a2d\u5b9a\u3092\u884c\u308f\u305a\u3001<strong>CreateObject<\/strong> \u95a2\u6570\u3092\u4f7f\u3063\u3066\u3001<strong>FileSystemObject\uff08FSO\uff09<\/strong> \u3092\u5229\u7528\u3057\u307e\u3059\u3002<br \/>\n    \u305f\u3060\u3057\u3001\u3053\u306e\u65b9\u6cd5\u306e\u5834\u5408\u3001\u53c2\u7167\u8a2d\u5b9a\u3092\u884c\u3063\u305f\u5834\u5408\u3068\u6bd4\u3079\u3066\u5b9f\u884c\u901f\u5ea6\u304c\u9045\u304f\u306a\u308a\u307e\u3059\u3002\u307e\u305f\u3001<strong>VBE\uff08Visual Basic Editor\uff09<\/strong>\u306e\u5165\u529b\u652f\u63f4\u6a5f\u80fd\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <span class=\"red\"><strong>\uff1cFileSystemObject \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\uff1e<\/strong><\/span><br \/>\n    <strong>Dim<\/strong> <em>fso<\/em> [ <strong>As Object<\/strong> ]<br \/>\n    <strong>Set<\/strong> <em>fso<\/em> = <strong>CreateObject<\/strong>(&#8220;Scripting.FileSystemObject&#8221;)<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>fso&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u4efb\u610f\u306e\u540d\u524d\uff08 <strong>FileSystemObject \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong> \u306e\u5909\u6570\u540d\uff09\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<br \/><\/div>\n<\/div>\n<br \/><br \/>\n<h2>FSO \u4f7f\u7528\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9 1<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"FSO\uff08\u53c2\u7167\u8a2d\u5b9a\u3092\u884c\u3046\uff09\u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample01_FSO()\r\n\r\n    '\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\r\n    \r\n    Dim FSO As New FileSystemObject\r\n    Dim FileName As String\r\n    \r\n    FileName = \"C:\\Documents\\memo01.txt\"\r\n    \r\n    If FSO.FileExists(FileName) Then\r\n    \r\n        MsgBox FileName & \" \u306f\u5b58\u5728\u3057\u307e\u3059\"\r\n    \r\n    Else\r\n    \r\n        MsgBox FileName & \" \u306f\u5b58\u5728\u3057\u307e\u305b\u3093\"\r\n    \r\n    End If\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\/2016\/03\/fsosample.jpg?ssl=1\" rel=\"lightbox[5259]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/fsosample.jpg?resize=298%2C155&#038;ssl=1\" alt=\"FSO\uff08\u53c2\u7167\u8a2d\u5b9a\uff09\u4f7f\u7528\u4f8b\" width=\"298\" height=\"155\" class=\"alignnone size-full wp-image-5268\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9 2<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"FSO\uff08\u53c2\u7167\u8a2d\u5b9a\u3092\u884c\u308f\u306a\u3044\uff09\u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample02_FSO()\r\n\r\n    '\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u30fc\u5185\u306e\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u540d\u524d\u3092\u53d6\u5f97\u3059\u308b\r\n    \r\n    Dim FSO As Object\r\n    Dim TargetFolder As Object\r\n    Dim myFiles As Object\r\n    Dim myFile As Object\r\n    Dim strFiles As String\r\n    \r\n    Set FSO = CreateObject(\"Scripting.FileSystemObject\")\r\n    Set TargetFolder = FSO.GetFolder(\"C:\\Documents\\data\")\r\n    Set myFiles = TargetFolder.Files\r\n    \r\n    If myFiles.Count = 0 Then\r\n        \r\n        MsgBox \"\u30d5\u30a1\u30a4\u30eb\u306f\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\"\r\n        Exit Sub\r\n    \r\n    End If\r\n    \r\n    For Each myFile In myFiles\r\n    \r\n        strFiles = strFiles & myFile.Name & vbCrLf\r\n    \r\n    Next\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 2<\/h3>\n<p><a href=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/fsocreateobjectsample.jpg?ssl=1\" rel=\"lightbox[5259]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/fsocreateobjectsample.jpg?resize=168%2C215&#038;ssl=1\" alt=\"FSO\uff08\u53c2\u7167\u8a2d\u5b9a\u3057\u306a\u3044\uff09\u4f7f\u7528\u4f8b\" width=\"168\" height=\"215\" class=\"alignnone size-full wp-image-5269\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08FileSystemObject\uff09 FileSys &#8230; <\/p>\n","protected":false},"author":1,"featured_media":5303,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[836],"tags":[721,693,722,833,834,38,835],"jetpack_featured_media_url":"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/03\/FSO_settings01-580x396-1.jpg?fit=580%2C396&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1mP","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5259"}],"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=5259"}],"version-history":[{"count":8,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5259\/revisions"}],"predecessor-version":[{"id":5948,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5259\/revisions\/5948"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/5303"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=5259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=5259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=5259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}