<?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/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>aruy.net &#187; ノーツ</title>
	<atom:link href="http://aruy.net/archives/category/%e3%83%8e%e3%83%bc%e3%83%84/feed" rel="self" type="application/rss+xml" />
	<link>http://aruy.net</link>
	<description>ちゃんとプログラムが書けるようになりたい。</description>
	<lastBuildDate>Tue, 15 Nov 2011 15:00:23 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aruy.net/archives/category/%e3%83%8e%e3%83%bc%e3%83%84/feed" />
		<item>
		<title>Notes/Ruby フィールドリスト作成</title>
		<link>http://aruy.net/archives/149</link>
		<comments>http://aruy.net/archives/149#comments</comments>
		<pubDate>Tue, 13 Jan 2009 10:46:19 +0000</pubDate>
		<dc:creator>aruy</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[ノーツ]]></category>
		<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://aruy.net/?p=149</guid>
		<description><![CDATA[NotesDBのフィールドリストが必要になったので 簡単にRubyで書きました。 たいした内容じゃないので公開する必要なんてないんだけど 以前も書いたのですが、どっかにいっちゃって困ったのでなくさないようにメモ #!ru [...]<p><a href="http://aruy.net/archives/149">Notes/Ruby フィールドリスト作成</a> is a post from: <a href="http://aruy.net">aruy.net</a></p>
]]></description>
			<content:encoded><![CDATA[<p>NotesDBのフィールドリストが必要になったので<br />
簡単にRubyで書きました。</p>
<p>たいした内容じゃないので公開する必要なんてないんだけど<br />
以前も書いたのですが、どっかにいっちゃって困ったのでなくさないようにメモ</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!ruby -Ks</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'win32ole'</span>
ns = WIN32OLE.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Notes.NotesSession'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
sv = <span style="color:#CC0066; font-weight:bold;">gets</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
fn = <span style="color:#CC0066; font-weight:bold;">gets</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
&nbsp;
db = ns.<span style="color:#9900CC;">GetDatabase</span><span style="color:#006600; font-weight:bold;">&#40;</span>sv, fn<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
title = db.<span style="color:#9900CC;">Title</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;DBTitle:#{title}&quot;</span>
&nbsp;
forms = db.<span style="color:#9900CC;">Forms</span>
&nbsp;
forms.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;FormTitle:#{form.name}&quot;</span>
  fields = form.<span style="color:#9900CC;">fields</span>
  fields.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>field<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> field
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p><a href="http://aruy.net/archives/149">Notes/Ruby フィールドリスト作成</a> is a post from: <a href="http://aruy.net">aruy.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://aruy.net/archives/149/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aruy.net/archives/149" />
	</item>
		<item>
		<title>Notes 添付ファイル その2</title>
		<link>http://aruy.net/archives/125</link>
		<comments>http://aruy.net/archives/125#comments</comments>
		<pubDate>Tue, 16 Dec 2008 09:48:11 +0000</pubDate>
		<dc:creator>aruy</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[ノーツ]]></category>
		<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://aruy.net/?p=125</guid>
		<description><![CDATA[RubyでNotesのメールを書き出す を参考に、Notes添付ファイルを一括出力する処理をRubyで書いてみました。 まんまコピーなんですが、忘れないように記録 全件対象で処理した場合、エラーが発生し落ちてしまったので [...]<p><a href="http://aruy.net/archives/125">Notes 添付ファイル その2</a> is a post from: <a href="http://aruy.net">aruy.net</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://d.hatena.ne.jp/jitte/20060429/1146289698">RubyでNotesのメールを書き出す</a><br />
を参考に、Notes添付ファイルを一括出力する処理をRubyで書いてみました。<br />
まんまコピーなんですが、忘れないように記録</p>
<p>全件対象で処理した場合、エラーが発生し落ちてしまったので、<br />
@Attachmentsで抽出したViewを作成し処理対象を添付ファイルが<br />
存在する文書のみに変更しました。</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'win32ole'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Log
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>s<span style="color:#006600; font-weight:bold;">&#41;</span>
    @@logger <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> x <span style="color:#006600; font-weight:bold;">&#125;</span>
    @@logger.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>s<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> Log.<span style="color:#9900CC;">register_logger</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    @@logger = <span style="color:#CC0066; font-weight:bold;">p</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Notes
  <span style="color:#9966CC; font-weight:bold;">class</span> Session
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>server, dbname<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@server</span>, <span style="color:#0066ff; font-weight:bold;">@dbname</span> = server, dbname
      <span style="color:#0066ff; font-weight:bold;">@session</span> = WIN32OLE.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Notes.NotesSession'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">or</span> <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
      <span style="color:#0066ff; font-weight:bold;">@db</span> = <span style="color:#0066ff; font-weight:bold;">@session</span>.<span style="color:#9900CC;">GetDatabase</span><span style="color:#006600; font-weight:bold;">&#40;</span>@Server, <span style="color:#0066ff; font-weight:bold;">@dbname</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> each
      view = <span style="color:#0066ff; font-weight:bold;">@db</span>.<span style="color:#9900CC;">GetView</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Attachments'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      doc = view.<span style="color:#9900CC;">GetFirstDocument</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">while</span> doc
        <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#6666ff; font-weight:bold;">Notes::Document</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>doc<span style="color:#006600; font-weight:bold;">&#41;</span>
        doc = view.<span style="color:#9900CC;">GetNextDocument</span><span style="color:#006600; font-weight:bold;">&#40;</span>doc<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#CC00FF; font-weight:bold;">Enumerable</span>
&nbsp;
    <span style="color:#008000; font-style:italic;">#添付ファイルをdirに書き出す</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> extract_files<span style="color:#006600; font-weight:bold;">&#40;</span>dir<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>doc<span style="color:#006600; font-weight:bold;">|</span>
        doc.<span style="color:#9900CC;">each_attachment</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span>
          name = obj.<span style="color:#9900CC;">name</span>
          Log.<span style="color:#9900CC;">new</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>#{name}&quot;</span>
&nbsp;
          <span style="color:#008000; font-style:italic;">#対象外の拡張子をチェックする</span>
          ext = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">extname</span><span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">downcase</span>
          <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>htm html csv pif scr com bat<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>ext<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
          <span style="color:#008000; font-style:italic;">#書き出しメソッドを呼び出し</span>
          doc.<span style="color:#9900CC;">extract_file</span><span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#996600;">&quot;#{dir}/#{name}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;">#添付ファイルをdir/fromに書き出す</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> extract_files_by_sender<span style="color:#006600; font-weight:bold;">&#40;</span>dir, body_hash = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>doc<span style="color:#006600; font-weight:bold;">|</span>
        k = doc.<span style="color:#9900CC;">unid</span>
&nbsp;
        <span style="color:#008000; font-style:italic;">#出力先の作成</span>
        extract_dir = <span style="color:#996600;">&quot;#{dir}/#{k}&quot;</span>
        <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">mkdir</span><span style="color:#006600; font-weight:bold;">&#40;</span>extract_dir<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exist</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>extract_dir<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
        doc.<span style="color:#9900CC;">each_attachment</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span>
          name = obj.<span style="color:#9900CC;">name</span>
          Log.<span style="color:#9900CC;">new</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>#{name}&quot;</span>
          ext  = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">extname</span><span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">downcase</span>
          <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>htm html csv pif com bat<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>ext<span style="color:#006600; font-weight:bold;">&#41;</span>
          doc.<span style="color:#9900CC;">extract_file</span><span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#996600;">&quot;#{extract_dir}/#{name}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> Document
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>doc<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@doc</span> = doc
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> each_attachment
      a = <span style="color:#0066ff; font-weight:bold;">@doc</span>.<span style="color:#9900CC;">Items</span> <span style="color:#9966CC; font-weight:bold;">or</span> <span style="color:#0000FF; font-weight:bold;">return</span>
      a.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#6666ff; font-weight:bold;">Notes::Attachment</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>obj<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> obj.<span style="color:#9900CC;">Type</span> == <span style="color:#006666;">1084</span> <span style="color:#008000; font-style:italic;">#ATTACHMENT</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> unid;    <span style="color:#0066ff; font-weight:bold;">@doc</span>.<span style="color:#9900CC;">UniversalID</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> extract_file<span style="color:#006600; font-weight:bold;">&#40;</span>name, path<span style="color:#006600; font-weight:bold;">&#41;</span>
      obj = <span style="color:#0066ff; font-weight:bold;">@doc</span>.<span style="color:#9900CC;">GetAttachment</span><span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">or</span> <span style="color:#0000FF; font-weight:bold;">return</span>
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        obj.<span style="color:#9900CC;">ExtractFile</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
        Log.<span style="color:#9900CC;">new</span> <span style="color:#996600;">&quot;**** #{e.message} ****&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> Attachment
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>obj<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@obj</span> = obj
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> extract_file<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@obj</span>.<span style="color:#9900CC;">ExtractFile</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> name
      <span style="color:#0066ff; font-weight:bold;">@obj</span>.<span style="color:#9900CC;">Values</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>呼出し側</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'notesruby'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'optparse'</span>
&nbsp;
opt_hash = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span>
opt_hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'dir'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'.'</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> ARGV
ARGV.<span style="color:#9900CC;">options</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>opt<span style="color:#006600; font-weight:bold;">|</span>
    opt.<span style="color:#9900CC;">on</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'-d [dir]'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>v<span style="color:#006600; font-weight:bold;">|</span> opt_hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'dir'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = v <span style="color:#006600; font-weight:bold;">&#125;</span>
    opt.<span style="color:#9900CC;">on</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'-s'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>v<span style="color:#006600; font-weight:bold;">|</span> opt_hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'same_folder'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = v <span style="color:#006600; font-weight:bold;">&#125;</span>
    opt.<span style="color:#9900CC;">parse</span>!
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
dir = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>opt_hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'dir'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> !<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">writable</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>dir<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> ARGV.<span style="color:#9900CC;">size</span> == <span style="color:#006666;">0</span>
  Log.<span style="color:#9900CC;">new</span> <span style="color:#996600;">&quot;Usage: ruby #{$0} [-s] [-d dir] file [file...]&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">exit</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
body_hash = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span>
ARGV.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>arg<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> m = arg.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>@<span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    nsf, svr = m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    nsf, svr = <span style="color:#006600; font-weight:bold;">&#91;</span>arg, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">if</span> db = <span style="color:#6666ff; font-weight:bold;">Notes::Session</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>svr, nsf<span style="color:#006600; font-weight:bold;">&#41;</span>
    Log.<span style="color:#9900CC;">new</span> <span style="color:#996600;">&quot;添付ファイル抽出...(#{arg})&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> opt_hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'same_folder'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      db.<span style="color:#9900CC;">extract_files</span><span style="color:#006600; font-weight:bold;">&#40;</span>dir<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      db.<span style="color:#9900CC;">extract_files_by_sender</span><span style="color:#006600; font-weight:bold;">&#40;</span>dir, body_hash<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><a href="http://aruy.net/archives/125">Notes 添付ファイル その2</a> is a post from: <a href="http://aruy.net">aruy.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://aruy.net/archives/125/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aruy.net/archives/125" />
	</item>
		<item>
		<title>Notes　添付ファイル</title>
		<link>http://aruy.net/archives/13</link>
		<comments>http://aruy.net/archives/13#comments</comments>
		<pubDate>Wed, 22 Oct 2008 07:05:00 +0000</pubDate>
		<dc:creator>aruy</dc:creator>
				<category><![CDATA[ノーツ]]></category>
		<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://aruy.net/?p=13</guid>
		<description><![CDATA[ノーツ移行に伴って添付ファイル一括書き出しを書いたのでメモ Viewアクションから実行 文書IDごとにディレクトリを切って添付ファイルを保存 これですむといいな。 Sub Click(Source As Button)  [...]<p><a href="http://aruy.net/archives/13">Notes　添付ファイル</a> is a post from: <a href="http://aruy.net">aruy.net</a></p>
]]></description>
			<content:encoded><![CDATA[<p>ノーツ移行に伴って添付ファイル一括書き出しを書いたのでメモ<br />
Viewアクションから実行<br />
文書IDごとにディレクトリを切って添付ファイルを保存<br />
これですむといいな。</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #E56717; font-weight: bold;">Sub</span> Click(Source <span style="color: #151B8D; font-weight: bold;">As</span> Button)
	<span style="color: #151B8D; font-weight: bold;">Dim</span> session <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> NotesSession
	<span style="color: #151B8D; font-weight: bold;">Dim</span> db <span style="color: #151B8D; font-weight: bold;">As</span> NotesDatabase
	<span style="color: #151B8D; font-weight: bold;">Dim</span> collection <span style="color: #151B8D; font-weight: bold;">As</span> NotesDocumentCollection
	<span style="color: #151B8D; font-weight: bold;">Dim</span> doc <span style="color: #151B8D; font-weight: bold;">As</span> NotesDocument
	<span style="color: #151B8D; font-weight: bold;">Dim</span> rtitem <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>
	<span style="color: #151B8D; font-weight: bold;">Dim</span> itemname <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>
	<span style="color: #151B8D; font-weight: bold;">Dim</span> item <span style="color: #151B8D; font-weight: bold;">As</span> NotesItem
	<span style="color: #151B8D; font-weight: bold;">Dim</span> <span style="color: #F660AB; font-weight: bold;">object</span> <span style="color: #151B8D; font-weight: bold;">As</span> NotesEmbeddedObject
&nbsp;
	<span style="color: #151B8D; font-weight: bold;">Set</span> db = session.CurrentDatabase
	<span style="color: #151B8D; font-weight: bold;">Set</span> collection = db.UnprocessedDocuments
&nbsp;
	<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> collection.Count
		<span style="color: #151B8D; font-weight: bold;">Set</span> doc = collection.GetNthDocument( i )
		<span style="color: #8D38C9; font-weight: bold;">If</span> doc.HasEmbedded <span style="color: #8D38C9; font-weight: bold;">Then</span>
			<span style="color: #8D38C9; font-weight: bold;">Do</span> <span style="color: #8D38C9; font-weight: bold;">While</span> doc.HasItem( <span style="color: #800000;">&quot;$FILE&quot;</span> )
				<span style="color: #151B8D; font-weight: bold;">Set</span> item = doc.GetFirstItem( <span style="color: #800000;">&quot;$FILE&quot;</span> )
				<span style="color: #8D38C9; font-weight: bold;">If</span> item.<span style="color: #151B8D; font-weight: bold;">Type</span> = ATTACHMENT <span style="color: #8D38C9; font-weight: bold;">Then</span>
					folderpath = <span style="color: #800000;">&quot;c:\temp&quot;</span> &amp; <span style="color: #800000;">&quot;\&quot;</span> &amp; doc.universalid
					<span style="color: #8D38C9; font-weight: bold;">If</span> Dir(folderpath,16)=<span style="color: #800000;">&quot;&quot;</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
						Mkdir folderpath
					<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
					itemname = doc.GetItemValue( <span style="color: #800000;">&quot;$FILE&quot;</span> )
						<span style="color: #151B8D; font-weight: bold;">Set</span> <span style="color: #F660AB; font-weight: bold;">object</span> = doc.GetAttachment( itemname(0) )
					<span style="color: #E56717; font-weight: bold;">Call</span> <span style="color: #F660AB; font-weight: bold;">object</span>.ExtractFile( folderpath &amp; <span style="color: #800000;">&quot;\&quot;</span> &amp; itemname(0))
				<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
				<span style="color: #E56717; font-weight: bold;">Call</span> item.Remove
			<span style="color: #8D38C9; font-weight: bold;">Loop</span>
		<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
	<span style="color: #8D38C9; font-weight: bold;">Next</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span></pre></div></div>

<p><a href="http://aruy.net/archives/13">Notes　添付ファイル</a> is a post from: <a href="http://aruy.net">aruy.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://aruy.net/archives/13/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aruy.net/archives/13" />
	</item>
	</channel>
</rss>

