<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mogice &#8211; REONTOSANTA</title>
	<atom:link href="https://knowledge.reontosanta.com/archives/author/mogice/feed" rel="self" type="application/rss+xml" />
	<link>https://knowledge.reontosanta.com</link>
	<description>Collection of personal knowledge</description>
	<lastBuildDate>Thu, 13 Aug 2020 00:05:00 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<atom:link rel='hub' href='https://knowledge.reontosanta.com/?pushpress=hub'/>
<site xmlns="com-wordpress:feed-additions:1">83369280</site>	<item>
		<title>WordPressでウィジェットを追加する</title>
		<link>https://knowledge.reontosanta.com/archives/1334</link>
					<comments>https://knowledge.reontosanta.com/archives/1334#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Sun, 19 Nov 2017 20:57:04 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://knowledge.reontosanta.com/?p=1334</guid>

					<description><![CDATA[WordPressでウィジェットを任意の位置に挿入するには、func&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<p>WordPressでウィジェットを任意の位置に挿入するには、function.phpとstyle.cssに記述を追加する。</p>
<p>以下は表示位置ごとのサンプルになる。</p>
<h2>投稿本文中(最初のH2見出し手前)ウィジェットの追加</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">///////////////////////////////////////
// 投稿本文中ウィジェットの追加
///////////////////////////////////////
register_sidebars(1,
  array(
  'name'=&gt;'投稿本文中',
  'id' =&gt; 'widget-in-article',
  'description' =&gt; '投稿本文中に表示されるウイジェット。文中最初のH2タグの手前に表示されます。',
  'before_widget' =&gt; '&lt;div id="%1$s" class="widget-in-article %2$s"&gt;',
  'after_widget' =&gt; '&lt;/div&gt;',
  'before_title' =&gt; '&lt;div class="widget-in-article-title"&gt;',
  'after_title' =&gt; '&lt;/div&gt;',
));

///////////////////////////////////////
//H2見出しを判別する正規表現を定数にする
///////////////////////////////////////
define('H2_REG', '/&lt;h2.*?&gt;/i');//H2見出しのパターン

///////////////////////////////////////
//本文中にH2見出しが最初に含まれている箇所を返す（含まれない場合はnullを返す）
//H3-H6しか使っていない場合は、h2部分を変更してください
///////////////////////////////////////
function get_h2_included_in_body( $the_content ){
  if ( preg_match( H2_REG, $the_content, $h2results )) {//H2見出しが本文中にあるかどうか
    return $h2results[0];
  }
}

///////////////////////////////////////
// 投稿本文中の最初のH2見出し手前にウィジェットを追加する処理
///////////////////////////////////////
add_filter( 'the_content', function ($the_content) {
  if ( is_single() &amp;&amp; //投稿ページのとき、固定ページも表示する場合はis_singular()にする
       is_active_sidebar( 'widget-in-article' ) //ウィジェットが設定されているとき
  ) {
    //広告（AdSense）タグを記入
    ob_start();//バッファリング
    dynamic_sidebar( 'widget-in-article' );//本文中ウィジェットの表示
    $ad_template = ob_get_clean();
    $h2result = get_h2_included_in_body( $the_content );//本文にH2タグが含まれていれば取得
    if ( $h2result ) {//H2見出しが本文中にある場合のみ
      //最初のH2の手前に広告を挿入（最初のH2を置換）
      $count = 1;
      $the_content = preg_replace(H2_REG, $ad_template.$h2result, $the_content, $count);
    }
  }
  return $the_content;
});</pre><p></p><pre class="urvanov-syntax-highlighter-plain-tag">/* 投稿本文中ウィジェットのスタイル */
.widget-in-article {
  text-align: center;
}</pre><p></p>
<div class="knowl-content" style="margin-top: 40px;" id="knowl-1857332503"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="4196732648" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><h2>投稿本文下ウィジェットの追加</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">///////////////////////////////////////
// 投稿本文下ウィジェットの追加
///////////////////////////////////////
register_sidebars(1,
  array(
  'name'=&gt;'投稿本文下',
  'id' =&gt; 'widget-bottom-article',
  'description' =&gt; '投稿本文下に表示されるウイジェット。投稿本文の後に表示されます。',
  'before_widget' =&gt; '&lt;div id="%1$s" class="widget-bottom-article %2$s"&gt;',
  'after_widget' =&gt; '&lt;/div&gt;',
  'before_title' =&gt; '&lt;div class="widget-bottom-article-title"&gt;',
  'after_title' =&gt; '&lt;/div&gt;',
));

///////////////////////////////////////
// 投稿本文下にウィジェットを追加する処理
///////////////////////////////////////
add_filter( 'the_content', function ($the_content) {
  if ( is_single() &amp;&amp; //投稿ページのとき、固定ページも表示する場合はis_singular()にする
       is_active_sidebar( 'widget-bottom-article' ) //ウィジェットが設定されているとき
  ) {
    //広告（AdSense）タグを記入
    ob_start();//バッファリング
    dynamic_sidebar( 'widget-bottom-article' );//本文下ウィジェットの表示
    $ad_template = ob_get_clean();
    $the_content .= $ad_template;
  }
  return $the_content;
});</pre><p></p><pre class="urvanov-syntax-highlighter-plain-tag">/* 投稿本文下ウィジェットのスタイル */
.widget-bottom-article {
  text-align: center;
}</pre><p></p>
<h2>フッター上ウィジェットの追加</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">///////////////////////////////////////
// フッター上ウィジェットの追加
///////////////////////////////////////
register_sidebars(1,
  array(
  'name'=&gt;'フッター上',
  'id' =&gt; 'widget-top-footer',
  'description' =&gt; 'フッター上に表示されるウイジェット。',
  'before_widget' =&gt; '&lt;div id="%1$s" class="widget-top-footer %2$s"&gt;',
  'after_widget' =&gt; '&lt;/div&gt;',
  'before_title' =&gt; '&lt;div class="widget-top-footer-title"&gt;',
  'after_title' =&gt; '&lt;/div&gt;',
));

///////////////////////////////////////
// フッター上にウィジェットを追加する処理
///////////////////////////////////////
add_action( 'get_footer', function () {
  if ( is_active_sidebar( 'widget-top-footer' ) //ウィジェットが設定されているとき
  ) {
    //広告（AdSense）タグを記入
    ob_start();//バッファリング
    dynamic_sidebar( 'widget-top-footer' );//フッター上ウィジェットの表示
    echo ob_get_clean();
  }
});</pre><p></p><pre class="urvanov-syntax-highlighter-plain-tag">/* フッター上ウィジェットのスタイル */
.widget-top-footer {
  text-align: center;
}</pre><p></p>
<h2>ヘッダー下ウィジェットの追加</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
  include(TEMPLATEPATH . '/header.php');
  dynamic_sidebar('widget-bottom-header');
?&gt;</pre><p></p><pre class="urvanov-syntax-highlighter-plain-tag">/* ヘッダー下ウィジェットのスタイル */
.widget-bottom-header {
  text-align: center;
}</pre><p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-3511143366"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-1093338559"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1334/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1334</post-id>	</item>
		<item>
		<title>WordPressでコメントに入力されたurlを制御する</title>
		<link>https://knowledge.reontosanta.com/archives/1327</link>
					<comments>https://knowledge.reontosanta.com/archives/1327#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Sat, 14 Oct 2017 20:56:20 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://knowledge.reontosanta.com/?p=1327</guid>

					<description><![CDATA[WordPressでコメントに書かれたurlがリンクにならないように&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<p>WordPressでコメントに書かれたurlがリンクにならないようにするには、functions.phpに以下の記述を追加する。</p><pre class="urvanov-syntax-highlighter-plain-tag">///////////////////////////////////////
// コメントに書かれたurlがリンクにならないようにする
///////////////////////////////////////
remove_filter( 'comment_text', 'make_clickable', 9);</pre><p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-252238829"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-307221967"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1327/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1327</post-id>	</item>
		<item>
		<title>WordPressで子テーマを作成する</title>
		<link>https://knowledge.reontosanta.com/archives/1325</link>
					<comments>https://knowledge.reontosanta.com/archives/1325#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Mon, 04 Sep 2017 20:55:13 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://knowledge.reontosanta.com/?p=1325</guid>

					<description><![CDATA[WordPressで子テーマは、子テーマディレクトリと2つのファイル&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<p>WordPressで子テーマは、子テーマディレクトリと2つのファイル(style.css と functions.php) から構成される。</p>
<h2>子テーマディレクトリの作成</h2>
<p>wp-content/themes ディレクトリ下に子テーマディレクトリを作成する。</p>
<p>子テーマディレクトリの名前には最後に &#8216;(親テーマ名)_child&#8217; を付けるとわかりやすい。</p>
<div class="knowl-content" style="margin-top: 40px;" id="knowl-1836363920"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="4196732648" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><h2>style.cssの作成</h2>
<p>子テーマディレクトリ下にstyle.cssを作成する。</p>
<p>最低限、Theme NameとTemplateのみの記述でOK。</p><pre class="urvanov-syntax-highlighter-plain-tag">/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/</pre><p></p>
<h2>functions.phpの作成</h2>
<p>子テーマディレクトリ下にfunctions.phpを作成する。</p>
<p>親テーマのスタイルシートをキューに入れる処理を記述する。</p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
///////////////////////////////////////
// 親テーマのスタイルシートをキューに入れる
///////////////////////////////////////
add_action( 'wp_enqueue_scripts', function () {
  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
});
?&gt;</pre><p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-2242725587"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-1368325043"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1325/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1325</post-id>	</item>
		<item>
		<title>Gitでの操作を取り消す</title>
		<link>https://knowledge.reontosanta.com/archives/1068</link>
					<comments>https://knowledge.reontosanta.com/archives/1068#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Sat, 26 Aug 2017 01:02:24 +0000</pubDate>
				<category><![CDATA[Git]]></category>
		<guid isPermaLink="false">http://knowledge.reontosanta.com/?p=1068</guid>

					<description><![CDATA[Gitでの取り消し操作には目的によりいくつかの方法がある。 ローカル&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<p>Gitでの取り消し操作には目的によりいくつかの方法がある。</p>
<h2>ローカルの変更取り消し</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$ git checkout .</pre><p>変更はこれで全部取り消すことができるが、新規追加したファイルに関しては削除されない為、完全に元に戻したい場合は別途削除する必要がある。</p><pre class="urvanov-syntax-highlighter-plain-tag">$ git clean -df .</pre><p></p>
<div class="knowl-content" style="margin-top: 40px;" id="knowl-3189426467"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="4196732648" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><h2>addを取り消し</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$ git reset HEAD .</pre><p>addの状態しか取り消されない為、変更も取り消したい場合はローカルの変更取り消し作業も行う必要がある。</p>
<h2>commitを取り消し</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$ git reset [&lt;mode&gt;] [&lt;commit&gt;] .</pre><p>modeのデフォルトは&#8211;mixedである為、変更したファイルはすべてそのままとなり、gitの履歴がだけが変わる。</p>
<p>変更したファイルも含めてすべて指定のcommit状態に戻したい場合は、modeに&#8211;hardを指定する。</p>
<p>また、&#8211;hardを指定した場合も新規追加のファイルは残ったままになっている為、完全に元に戻したい場合は別途削除する必要がある。</p>
<h2>pushを取り消し</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$ git revert [&lt;commit&gt;]
$ git push</pre><p>指定commitまでの変更を相殺するcommitを作成するというものなのでrevert後にpushすることでリモートが実質undoをしたような状態になる。</p>
<p>複数コミットを取り消したい場合は、-nオプションを指定する。</p><pre class="urvanov-syntax-highlighter-plain-tag">$ git revert -n [&lt;commit&gt;]
$ git revert -n [&lt;commit&gt;]
...
$ git commit
$ git push</pre><p>-nは&#8211;no-commitと同じオプションでその名の通り、自動でコミットをしないようにする。</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-2571260116"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-196382932"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1068/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1068</post-id>	</item>
		<item>
		<title>Windowsで現在開かれているファイルを表示・切断する</title>
		<link>https://knowledge.reontosanta.com/archives/1066</link>
					<comments>https://knowledge.reontosanta.com/archives/1066#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Tue, 25 Jul 2017 08:20:40 +0000</pubDate>
				<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">http://knowledge.reontosanta.com/?p=1066</guid>

					<description><![CDATA[openfiles コマンドでファイルを開いているプロセスを調べる &#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h2>openfiles コマンドでファイルを開いているプロセスを調べる</h2>
<p>Windowsにおいてファイルを編集したり削除しようとした場合、他のプロセスが開いていて編集・削除できないことがある。<br />
このような場合、ファイルを開いているプロセス(アプリケーションやサービスなど)を終了させてからファイルを編集・削除する必要があるが、openfiles コマンドを利用すればその調査をすることができる。</p>
<div class="knowl-content" style="margin-top: 40px;" id="knowl-1819939804"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="4196732648" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><h2>1.設定方法</h2>
<p>openfiles コマンド が機能するには事前に以下の設定、及び設定後の再起動が必要となる。</p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /local on
成功: システム グローバル フラグ 'maintain objects list' は有効になりました。
システムを再起動すると、変更が有効になります。</pre><p>※ネットワーク経由で他のユーザが開いているローカルのファイル(ローカルサーバの共有を使用して他のユーザが開いているファイル)一覧は &#8220;openfiles /local on&#8221;の設定をしなくても一覧表示可能。<br />
→openfiles /query /v で出力される。</p>
<h2>2.一覧表示</h2>
<p>現在開かれているファイルの一覧を表示するには以下のコマンドを実行する。</p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /query /v</pre><p>以下例では test.txtを開いているプロセスを表示している。<br />
ローカルファイルと共有ファイル(ネットワーク経由で他のサーバ開く)で結果が異なる。</p>
<h3>(1)ローカルファイルの場合</h3>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /query /v | findstr test.txt
408 Administrator 1340 Hidemaru.exe C:\temp\test.txt</pre><p>※秀丸の「ファイルの排他制御」「読み書き禁止」でファイルを排他的に開いた場合。</p>
<h3>(2)共有ファイルの場合(openfilesを実行しているサーバに対して、ネットワーク経由で他のユーザが開いているファイル）</h3>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /query | findstr test.txt
210 administrator Windows C:\temp\test.txt</pre><p>※openfiles コマンドはリモートコンピュータ上の情報を見ることも可能。</p><pre class="urvanov-syntax-highlighter-plain-tag">openfiles /query /s &lt;ipアドレス&gt; /u &lt;ユーザ名&gt; /p &lt;パスワード&gt;</pre><p></p>
<h2>3.切断方法（強制クローズ）</h2>
<p>・ローカルファイルの場合<br />
ローカルで開いているファイルは切断（強制クローズ）できない。ファイルを開いているアプリケーションを終了させる必要がある。(不明なプロセスがファイルを開いて削除できない場合などの強制ファイルクローズは不可)</p>
<p>・共有ファイルの場合<br />
openfilesを実行しているサーバに対して、ネットワーク経由で他のユーザが開いているファイルは切断(強制クローズ)が可能。<br />
以下の例ではネットワーク経由で開かれている test.txtを強制切断しています。</p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /query | findstr test.txt
210 administrator Windows C:\temp\test.txt</pre><p>上記ファイルはネットワーク経由でadministratorが共有を使用して test.txtを開いている。</p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /Disconnect /ID 210
成功: 開いているファイル "C:\temp\test.txt" への接続は切断されました。</pre><p>&nbsp;</p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /query | findstr test.txt
(結果無し）</pre><p>※ファイルを排他無しで開いている場合は開いているファイル一覧には表示されない。<br />
例として、秀丸の「ファイルの排他制御」が「しない」の場合、結果の一覧に表示されない。「ファイルの排他制御」が「上書きだけ禁止」あるいは「読み書き禁止」の場合は表示される。</p>
<h2>4.設定を戻す</h2>
<p>・/local on の設定を行うと性能が悪化する。<br />
従って設定が不要なら設定を戻すことを推奨する。</p><pre class="urvanov-syntax-highlighter-plain-tag">C:\&gt;openfiles /local off
成功: システム グローバル フラグ 'maintain objects list' は無効になりました。
システムを再起動すると、変更が有効になります。</pre><p>&nbsp;</p>
<h2>5.オプションについて</h2>
<h3>openfiles /Query [オプション]</h3>
<p>使用中の共有ファイルを表示する。<br />
「/Query」に続けて指定できるオプションは以下の通り。</p>
<p>オプション 説明オプション 説明<br />
/S 【コンピュータ名】 対象のコンピュータを指定する/S 【コンピュータ名】 対象のコンピュータを指定する<br />
/U 【ユーザ名】 「/S」オプションと併用して、対象のコンピュータにログインするためのユーザ名を指定する/U 【ユーザ名】 「/S」オプションと併用して、対象のコンピュータにログインするためのユーザ名を指定する<br />
/P 【パスワード】 「/S」「/U」オプションと併用して、対象のコンピュータにログインするためのパスワードを指定する/P 【パスワード】 「/S」「/U」オプションと併用して、対象のコンピュータにログインするためのパスワードを指定する<br />
/FO 【出力形式】 結果の出力形式を指定する。「TABLE」「LIST」「CSV」の中から指定可能/FO 【出力形式】 結果の出力形式を指定する。「TABLE」「LIST」「CSV」の中から指定可能<br />
/NH 結果の出力に項目名を含めない。「/FO TABLE」「/FO CSV」オプションと併用可能/NH 結果の出力に項目名を含めない。「/FO TABLE」「/FO CSV」オプションと併用可能<br />
/V 詳細情報を表示する/V 詳細情報を表示する<br />
/? ヘルプを表示する/? ヘルプを表示する</p>
<h3>openfiles /Disconnect [オプション]</h3>
<p>使用中の共有ファイルを「はい！使うの終わりね！」と切断する<br />
「/Disconnect」に続けて指定できるオプションは以下の通り。</p>
<p>オプション 説明オプション 説明<br />
/S 【コンピュータ名】 対象のコンピュータを指定する/S 【コンピュータ名】 対象のコンピュータを指定する<br />
/U 【ユーザ名】 「/S」オプションと併用して、対象のコンピュータにログインするためのユーザ名を指定する/U 【ユーザ名】 「/S」オプションと併用して、対象のコンピュータにログインするためのユーザ名を指定する<br />
/P 【パスワード】 「/S」「/U」オプションと併用して、対象のコンピュータにログインするためのパスワードを指定する/P 【パスワード】 「/S」「/U」オプションと併用して、対象のコンピュータにログインするためのパスワードを指定する<br />
/ID 【ID】 項目「ID」が【ID】のファイルを切断する/ID 【ID】 項目「ID」が【ID】のファイルを切断する<br />
/A 【アクセス】 項目「アクセス」が【アクセス】のファイルを切断する/A 【アクセス】 項目「アクセス」が【アクセス】のファイルを切断する<br />
/O 【オープンモード】 項目「オープンモード」が【オープンモード】のファイルを切断する/O 【オープンモード】 項目「オープンモード」が【オープンモード】のファイルを切断する<br />
/OP 【開いているファイル】 項目「開いているファイル」が【開いているファイル】のファイルを切断する/OP 【開いているファイル】 項目「開いているファイル」が【開いているファイル】のファイルを切断する<br />
/? ヘルプを表示する/? ヘルプを表示する</p>
<h3>openfiles /Local [オプション]</h3>
<p>ローカルで開いているファイルの表示/非表示を切り替える<br />
「/Local」に続けて指定できるオプションは以下の通り。<br />
オプション未指定の場合、現在の状態が確認できる。</p>
<p>オプション 説明オプション 説明<br />
ON ローカルで開いているファイルも表示するON ローカルで開いているファイルも表示する<br />
OFF ローカルで開いているファイルは表示しないOFF ローカルで開いているファイルは表示しない<br />
/? ヘルプを表示する/? ヘルプを表示する</p>
<p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-1011781935"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-2828113514"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1066/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1066</post-id>	</item>
		<item>
		<title>SQLServerでDataTableの内容を一度のSQLでデータベースに更新する</title>
		<link>https://knowledge.reontosanta.com/archives/1054</link>
					<comments>https://knowledge.reontosanta.com/archives/1054#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Fri, 23 Jun 2017 07:55:06 +0000</pubDate>
				<category><![CDATA[.Net(VB、C#)]]></category>
		<guid isPermaLink="false">http://knowledge.reontosanta.com/?p=1054</guid>

					<description><![CDATA[DataTable の内容をデータベースに登録、または更新したい場合&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<p>DataTable の内容をデータベースに登録、または更新したい場合がある。<br />
しかし、DataTable の行をループしながら行毎に INSERT 文や UPDATE 文を発行すると IO 負荷が高くなり、パフォーマンスが悪化する。<br />
そこで、SQL Server のユーザー定義テーブル型を使用することにより一括での更新が可能となる。</p>
<p>前提条件：SQL Server 2008 以降</p>
<p>&nbsp;</p>
<h2>IO負荷が高い例</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Sub Test(ByVal dt As DataTable)
    Dim con As New SqlConnection("connection string")
    Dim cmd As New SqlCommand
    Dim sql As New StringBuilder
    con.Open()
    cmd.Connection = con
    cmd.Parameters.Clear()
 
    'データテーブルの行分だけループしている悪い例
    For i As Integer = 0 To dt.Rows.Count - 1
        sql.AppendLine("INSERT INTO dbo.T_TEST ")
        sql.AppendLine("( ")
        sql.AppendLine("  CODE ")
        sql.AppendLine(") VALUES ( ")
        sql.AppendLine("  @Code ")
        sql.AppendLine("); ")
 
        'パラメータの作成
        Dim param = New SqlParameter("@Code", SqlDbType.Int, ParameterDirection.Input)
        param.Value = dt.Rows(i).Item(0).ToString()
        'パラメータを渡します。
        cmd.Parameters.Add(param)
 
        'プロシージャの実行
        cmd.CommandType = CommandType.Text
        cmd.CommandText = sql.ToString()
        cmd.ExecuteNonQuery
    Next i
End Sub</pre><p>まずは、悪例としてデータテーブルのレコードを 1 件ずつ INSERT していく方法。<br />
上記の方法だと件数が少なければ問題が無いように感じるが、１万件を超えてくるとそのパフォーマンスの悪さが目立ってくる。<br />
１万件のデータをループして INSERT すると１万回の IO 処理となり、オーバーヘッドが大きくなる。<br />
しかし、次の方法で INSERT すると１回の IO 処理で済む為、更新するデータ量は変わらないがかなりのパフォーマンス改善が見込まれる。</p>
<p>&nbsp;</p>
<div class="knowl-content" style="margin-top: 40px;" id="knowl-1715280681"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="4196732648" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><h2>DataTableをパラメータとして渡す</h2>
<p>DataTable をパラメータとして渡す為には、SQL Server 側にユーザー定義テーブル型を作成しておく必要がある。</p><pre class="urvanov-syntax-highlighter-plain-tag">CREATE TYPE TestTableType AS TABLE
(
  TestCode int NOT NULL
)
GO</pre><p>テーブルの定義と同様に括弧の中にフィールド定義を記述する。<br />
テーブルで定義できるフィールドはTableTypeでも定義可能。</p>
<p>続いて、プログラム側の処理。</p><pre class="urvanov-syntax-highlighter-plain-tag">Sub Test(ByVal dt As DataTable)
    Dim con As New SqlConnection("connection string")
    Dim cmd As New SqlCommand
    Dim sql As New StringBuilder
    con.Open()
    cmd.Connection = con
    cmd.Parameters.Clear()
 
    sql.AppendLine("INSERT INTO dbo.T_TEST ")
    sql.AppendLine("      ( ")
    sql.AppendLine("        CODE ")
    sql.AppendLine("      ) ")
    sql.AppendLine(" SELECT TestCode ")
    sql.AppendLine("   FROM @TestTable ")
    sql.AppendLine("  WHERE TestCode = @Code ")
    sql.AppendLine("); ")
  
    'パラメータの作成
    Dim params(1) As SqlParameters
    params(0) = New SqlParameter("@Code", SqlDbType.Int, ParameterDirection.Input)
    params(0).Value = 1
    params(1) = New SqlParameter("@TestTable", SqlDbType.Structured, ParameterDirection.Input)  'TypeにSqlDbType.Structuredを渡します。
    params(1).TypeName = "TestTableType"  'テーブルタイプの名称を渡します。
    params(1).Value = dt    '編集したデータテーブルを渡します。
    'パラメータ配列を渡します。
    cmd.Parameters.AddRange(params)
    'プロシージャの実行
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = sql.ToString()
    cmd.ExecuteNonQuery
End Sub</pre><p>ユーザー定義テーブル型を使用することで DataTable をテーブルのように渡すことができる為、一括で SELECT して INSERT または UPDATE が可能となる。</p>
<h4>&lt;注意事項&gt;</h4>
<ul>
<li>DataTable のフィールドはユーザー定義テーブル型のフィールドと一致している必要がある。</li>
<li>ユーザー定義テーブル型を渡す場合は、SqlDbType.Structured で渡す。</li>
</ul>
<p>&nbsp;</p>
<p>ユーザー定義テーブル型を作成しておく必要はあるが、こちらの方法であれば実行速度が圧倒的に速く、パフォーマンス改善が期待できる。<br />
デメリットとしては、ループせずに一括で更新する為、プログレスバーなどで進捗を表示することができない。</p>
<p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-2253381783"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-1088145337"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1054/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1054</post-id>	</item>
		<item>
		<title>SQLServerで断片化の状態に応じてIndexを再構築する</title>
		<link>https://knowledge.reontosanta.com/archives/1056</link>
					<comments>https://knowledge.reontosanta.com/archives/1056#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Tue, 30 May 2017 06:15:28 +0000</pubDate>
				<category><![CDATA[SQLServer]]></category>
		<guid isPermaLink="false">http://knowledge.reontosanta.com/?p=1056</guid>

					<description><![CDATA[SQLServerにおいて、インデックスが断片化してしまうとクエリの&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<p>SQLServerにおいて、インデックスが断片化してしまうとクエリのパフォーマンスが低下してくる。</p>
<p>インデックスの再構成(Reorganize)や再構築(Rebuild)を行うと断片化が解消される為、定期的にインデックスの再構成(Reorganize)や再構築(Rebuild)をすることでこれを解決することができる。</p>
<p>ただし、やみくもにデータベース内の全てのインデックスを再構成(Reorganize)や再構築(Rebuild)するとデータベースの規模が大きいほど、実行に多くの時間がかかってしまったり、ログファイルが大きくなりすぎてしまう。</p>
<p>そこで、断片化の状態を判断して再構成(Reorganize)または再構築(Rebuild)をする。</p>
<p>まず、インデックスの断片化の状態は <b>sys.dm_db_index_physical_stats </b>を使って調べることができる。</p>
<p><b>sys.dm_db_index_physical_stats </b>が返す <b>avg_fragmentation_in_percent </b>は論理的な断片化(インデックス内で順序が乱れたページ)の割合を示していて、再構成(Reorganize)または再構築(Rebuild)をするべきかどうかの判断の指標とすることができる。</p>
<p>例えば、以下のようなクエリで再構成(Reorganize)のクエリ、再構築(Rebuild)のクエリ、スキーマ名、テーブル名、インデックス名、インデックスID、オブジェクト内のパーティション番号、断片化の割合、インデックスページまたはデータページの合計数を取得することができる。</p>
<p><b>avg_fragmentation_in_percent &gt; 10</b> を指定することで、断片化率が 10 % 以上のインデックスを取得している。</p><pre class="urvanov-syntax-highlighter-plain-tag">SELECT
  'ALTER INDEX [' + C.name + '] ON [' + D.name + '].[' + B.name + '] REORGANIZE' AS ReorganizeCmd 
  , 'ALTER INDEX [' + C.name + '] ON [' + D.name + '].[' + B.name + '] REBUILD' AS RebuildCmd
  , D.name AS schemaname
  , B.name AS table_name
  , C.name AS index_name
  , C.index_id
  , A.partition_number
  , A.avg_fragmentation_in_percent
  , A.page_count 
FROM
  sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) AS A 
  INNER JOIN sys.objects AS B 
    ON A.object_id = B.object_id 
  INNER JOIN sys.indexes AS C 
    ON A.object_id = C.object_id 
    AND A.index_id = C.index_id 
  INNER JOIN sys.schemas D 
    ON B.schema_id = D.schema_id 
WHERE
  B.type = 'U' 
  AND C.index_id &gt; 0 
  AND A.page_count &gt; 1000 
  AND A.avg_fragmentation_in_percent &gt; 10 
ORDER BY
  A.avg_fragmentation_in_percent DESC</pre><p>インデックスの断片化の状態がわかったら、それによってインデックスを再構成(Reorganize)するか、または再構築(Rebuild)するか決定する。</p>
<p>例えば、10% 以上 30% 未満であれば再構成(Reorganize)、 30% 以上であれば再構築(Rebuild)するとすれば、上記のクエリで再構成のクエリ、または再構築のクエリを生成してそれぞれ実行する。</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-2643290807"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-1464989668"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1056/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1056</post-id>	</item>
		<item>
		<title>.net(VB、C#)でLINQを利用してCSVファイルを読み込む</title>
		<link>https://knowledge.reontosanta.com/archives/1006</link>
					<comments>https://knowledge.reontosanta.com/archives/1006#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Sun, 23 Apr 2017 01:25:46 +0000</pubDate>
				<category><![CDATA[.Net(VB、C#)]]></category>
		<guid isPermaLink="false">http://knowledge.reontosanta.com/?p=1006</guid>

					<description><![CDATA[LINQでCSVファイルを読み込む .NETには、CSVファイルを読&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h2>LINQでCSVファイルを読み込む</h2>
<p>.NETには、CSVファイルを読み取る際に便利なクラス(TextFieldParser)が「VB.NET」のライブラリに存在する。</p>
<p>このクラスを利用してCSVファイルをLINQで簡潔に扱えるようにする。</p>
<p>まず、CSVファイルへのコンテキストを生成する為のTextFieldクラスを作成する。</p>
<p>このクラスのContextメソッドでコンテキストを生成することでロジックを意識することなくCSVファイルの読み込みが可能になる。</p><pre class="urvanov-syntax-highlighter-plain-tag">Imports System.Text
Imports System.IO
Imports Microsoft.VisualBasic.FileIO

Public Class TextField
    ' 指定されたCSVファイルへのコンテキストを生成する
    Public Shared Function Context(path As String,
                                   Optional separator As String = ",",
                                   Optional myEncoding As Encoding = Nothing) As IEnumerable(Of String())

        Dim results As New List(Of String())

        Using stream As Stream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)

            Using parser As New TextFieldParser(stream, If(myEncoding, Encoding.UTF8), True, False)

                parser.TextFieldType = FieldType.Delimited
                parser.Delimiters = New String() {separator}
                parser.HasFieldsEnclosedInQuotes = True
                parser.TrimWhiteSpace = True

                While parser.EndOfData = False
                    Dim fields As String() = parser.ReadFields()
                    results.Add(fields)
                End While
            End Using
        End Using

        Return results
    End Function

End Class</pre><p>&nbsp;</p><pre class="urvanov-syntax-highlighter-plain-tag">using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.VisualBasic.FileIO;

namespace CS_CSVtoLINQ
{
    public class TextField
    {
        // 指定されたCSVファイルへのコンテキストを生成する
        public static IEnumerable&lt;string[]&gt; Context(string path,
                                                    string separator = ",",
                                                    Encoding encoding = null)
        {
            using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (TextFieldParser parser = new TextFieldParser(stream, encoding ?? Encoding.UTF8, true, false))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.Delimiters = new[] { separator };
                    parser.HasFieldsEnclosedInQuotes = true;
                    parser.TrimWhiteSpace = true;
                    while (parser.EndOfData == false)
                    {
                        string[] fields = parser.ReadFields();
                        yield return fields;
                    }
                }
            }
        }
    }
}</pre><p>&nbsp;</p>
<p>次は、実際にTextFieldクラスを利用してコンテキストを生成し、CSVファイルへアクセスしてLINQにより入力した条件に一致するレコードデータを表示するコードを記述する。</p>
<p>尚、AsParallel()メソッドを呼び出すことで条件判定をマルチスレッド化できるので、データ量が多い場合は、並列化による高速化が期待できる。</p><pre class="urvanov-syntax-highlighter-plain-tag">Imports System.Text
Imports System.IO

Module Module1

    Sub Main()
        Do
            ' 検索条件に使用するIDの入力を求める
            Console.WriteLine("IDを入力")
            Dim input As String = Console.ReadLine()

            ' 入力された値から終了判定
            If input.ToUpper = "END" OrElse input.ToUpper = "EXIT" Then
                ' "END"、または"EXIT"が入力された場合は終了
                Exit Do
            End If

            ' 指定したCSVファイルへのコンテキストを生成
            Dim context As IEnumerable(Of String()) = TextField.Context("CSV\\SAMPLE001.csv", ",", Encoding.GetEncoding("Shift_JIS"))

            ' 取得したコンテキストを入力されたIDをキーに検索
            Dim results As IEnumerable(Of String) =
                From fields In context.AsParallel()
                Where fields(0).Equals(input)
                Select String.Format("{0}：{1}", fields(1), fields(2))

            ' 検索結果を出力
            For Each result As String In results
                Console.WriteLine(result)
            Next
            Console.WriteLine("---END---")
        Loop

    End Sub

End Module</pre><p>&nbsp;</p><pre class="urvanov-syntax-highlighter-plain-tag">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CS_CSVtoLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                // 検索条件に使用するIDの入力を求める
                Console.WriteLine("IDを入力");
                string input = Console.ReadLine();

                // 入力された値から終了判定
                if (input.ToUpper().Equals("END") || input.ToUpper().Equals("EXIT"))
                {
                    // "END"、または"EXIT"が入力された場合は終了
                    break;
                }

                // 指定したCSVファイルへのコンテキストを生成
                IEnumerable&lt;string[]&gt; context = TextField.Context("CSV\\SAMPLE001.csv", ",", Encoding.GetEncoding("Shift_JIS"));

                // 取得したコンテキストを入力されたIDをキーに検索
                IEnumerable&lt;string&gt; results = 
                    from fields in context.AsParallel()
                    where fields[0].Equals(input)
                    select String.Format("{0}：{1}", fields[1], fields[2]);

                // 検索結果を出力
                foreach (string result in results)
                {
                    Console.WriteLine(result);
                }
                Console.WriteLine("---END---");
            }
        }
    }
}</pre><p>&nbsp;</p>
<p>複数ファイルを跨いで検索する場合は以下のように記述することができる。</p>
<p>※全てのファイルレイアウトが同じ場合</p><pre class="urvanov-syntax-highlighter-plain-tag">Imports System.Text
Imports System.IO

Module Module1

    Sub Main()
        Do
            ' 検索条件に使用するIDの入力を求める
            Console.WriteLine("IDを入力")
            Dim input As String = Console.ReadLine()

            ' 入力された値から終了判定
            If input.ToUpper = "END" OrElse input.ToUpper = "EXIT" Then
                ' "END"、または"EXIT"が入力された場合は終了
                Exit Do
            End If

            ' 指定したCSVファイルへのコンテキストを生成して、入力されたIDをキーに検索
            Dim results As IEnumerable(Of String) =
                From path In Directory.GetFiles("CSV", "*.csv", SearchOption.AllDirectories).AsParallel()
                From fields In TextField.Context(path, ",", Encoding.GetEncoding("Shift_JIS"))
                Where fields(0).Equals(input)
                Select String.Format("{0}：{1}", fields(1), fields(2))

            ' 検索結果を出力
            For Each result As String In results
                Console.WriteLine(result)
            Next
            Console.WriteLine("---END---")
        Loop

    End Sub

End Module</pre><p>&nbsp;</p><pre class="urvanov-syntax-highlighter-plain-tag">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CS_CSVtoLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                // 検索条件に使用するIDの入力を求める
                Console.WriteLine("IDを入力");
                string input = Console.ReadLine();

                // 入力された値から終了判定
                if (input.ToUpper().Equals("END") || input.ToUpper().Equals("EXIT"))
                {
                    // "END"、または"EXIT"が入力された場合は終了
                    break;
                }

                // 指定したCSVファイルへのコンテキストを生成して、入力されたIDをキーに検索
                IEnumerable&lt;string&gt; results = 
                    from path in Directory.GetFiles("CSV", "*.csv", SearchOption.AllDirectories).AsParallel()
                    from fields in TextField.Context(path, ",", Encoding.GetEncoding("Shift_JIS"))
                    where fields[0].Equals(input)
                    select String.Format("{0}：{1}", fields[1], fields[2]);

                // 検索結果を出力
                foreach (string result in results)
                {
                    Console.WriteLine(result);
                }
                Console.WriteLine("---END---");
            }
        }
    }
}</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-3237176348"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-2084043655"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1006/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1006</post-id>	</item>
		<item>
		<title>SQLServerで1つのクエリにより複数行をinsertする</title>
		<link>https://knowledge.reontosanta.com/archives/1015</link>
					<comments>https://knowledge.reontosanta.com/archives/1015#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Tue, 07 Mar 2017 05:26:18 +0000</pubDate>
				<category><![CDATA[SQLServer]]></category>
		<guid isPermaLink="false">http://knowledge.reontosanta.com/?p=1015</guid>

					<description><![CDATA[1つのクエリで、複数行をinsertする SQLServer2008&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h2>1つのクエリで、複数行をinsertする</h2>
<p>SQLServer2008以降では、INSERT文で追加行をカンマでつなげることで実現できる。</p>
<p>なお、一度に追加できる最大行数は、1000行となる。</p><pre class="urvanov-syntax-highlighter-plain-tag">INSERT 
INTO test_table(col1, col2) 
VALUES
  (value1, value2)
  , (value1, value2)</pre><p>&nbsp;</p>
<p>ちなみに、SQLServer2005以前では複数行のINSERTは動作しないので、以下のような方法をとることになる。</p><pre class="urvanov-syntax-highlighter-plain-tag">INSERT 
INTO dbo.MyTable(C1, C2) 
SELECT
  Value1
  , Value2 
UNION ALL 
SELECT
  Value1
  , Value2 
UNION ALL 
SELECT
  Value1
  , Value2</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-4146256557"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-3337096376"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1015/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1015</post-id>	</item>
		<item>
		<title>SQLServerで日付範囲から日(または月)ごとのデータを作成する</title>
		<link>https://knowledge.reontosanta.com/archives/1013</link>
					<comments>https://knowledge.reontosanta.com/archives/1013#respond</comments>
		
		<dc:creator><![CDATA[mogice]]></dc:creator>
		<pubDate>Mon, 13 Feb 2017 23:29:39 +0000</pubDate>
				<category><![CDATA[SQLServer]]></category>
		<guid isPermaLink="false">http://knowledge.reontosanta.com/?p=1013</guid>

					<description><![CDATA[日付範囲から日ごと、または月ごとに年月日(月ごとの場合、日は1日)を&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h2>日付範囲から日ごと、または月ごとに年月日(月ごとの場合、日は1日)を作成する</h2>
<p>”2017年1月1日から2017年1月31日まで”のようなFrom/Toの日付範囲があり、そこからカレンダーのように日ごとのデータを取得したい場合、以下のような共通テーブル式(CTE:Common Table Expression)を利用した再帰クエリで作成することができる。</p><pre class="urvanov-syntax-highlighter-plain-tag">WITH DateTable(MyDate) AS ( 
  SELECT
    CONVERT(DATETIME, '2017/01/01') 
  UNION ALL 
  SELECT
    DATEADD(d, 1, MyDate) 
  FROM
    DateTable 
  WHERE
    MyDate &lt; CONVERT(DATETIME, '2017/01/31')
) 
SELECT
  MyDate 
FROM
  DateTable</pre><p>&nbsp;</p>
<p>また、月ごと(日は1日)にデータを取得したい場合は以下のクエリで作成できる。</p><pre class="urvanov-syntax-highlighter-plain-tag">WITH MonthTable(YearMonth) AS ( 
  SELECT
    CONVERT(DATETIME, '2016/12/01') 
  UNION ALL 
  SELECT
    DATEADD(m, 1, YearMonth) 
  FROM
    MonthTable 
  WHERE
    YearMonth &lt; CONVERT(DATETIME, '2017/03/01')
) 
SELECT
  YearMonth 
FROM
  MonthTable</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<div class="knowl-after-content-ad" style="margin-top: 40px;" id="knowl-3263577957"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="2719999442" 
data-ad-format="auto"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div><div class="knowl-after-content-relation" id="knowl-2999065490"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8913642688016174" crossorigin="anonymous"></script><ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-8913642688016174" 
data-ad-slot="7848218644" 
data-ad-format="autorelaxed"></ins>
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://knowledge.reontosanta.com/archives/1013/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1013</post-id>	</item>
	</channel>
</rss>
