62°

c# everything扫描共享盘示例

背景

由于我们公司不同部门文件都放在共享盘中,我们需要将公盘文件上传阿里云或ftp,做增量查询(只查近今天的文件)
由于扫描公盘需求越来越多,数据量越来越大,之前通过递归扫描磁盘的方式太慢。

所以研究通过everything搜索文件方式替换之前的方式。 研究下来发现该方式扫描磁盘速度非常快。

那么废话不多说,直接上代码。

 

如果需要扫描共享盘的话:

(如果是本地磁盘可以忽略)

1.需要安装一下everything,在选项-文件夹-添加一下你的文件目录

2.需要将Everything32.dll copy到你的bin目录下

3.可以copy代码,运行

 [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern int Everything_SetSearchW(string lpSearchString);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMatchPath(bool bEnable);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMatchCase(bool bEnable);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMatchWholeWord(bool bEnable);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetRegex(bool bEnable);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMax(int dwMax);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetOffset(int dwOffset);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetReplyWindow(IntPtr hWnd);
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetReplyID(int nId);
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span><span style="color: #000000;"> Everything_GetMatchPath();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span><span style="color: #000000;"> Everything_GetMatchCase();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span><span style="color: #000000;"> Everything_GetMatchWholeWord();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span><span style="color: #000000;"> Everything_GetRegex();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span><span style="color: #000000;"> UInt32 Everything_GetMax();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span><span style="color: #000000;"> UInt32 Everything_GetOffset();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">string</span><span style="color: #000000;"> Everything_GetSearch();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetLastError();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span><span style="color: #000000;"> IntPtr Everything_GetReplyWindow();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetReplyID();

    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span> Everything_QueryW(<span style="color: #0000ff;">bool</span><span style="color: #000000;"> bWait);

    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span> Everything_IsQueryReply(<span style="color: #0000ff;">int</span> message, IntPtr wParam, IntPtr lParam, <span style="color: #0000ff;">uint</span><span style="color: #000000;"> nId);

    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> Everything_SortResultsByPath();

    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetNumFileResults();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetNumFolderResults();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetNumResults();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetTotFileResults();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetTotFolderResults();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Everything_GetTotResults();
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span> Everything_IsVolumeResult(<span style="color: #0000ff;">int</span><span style="color: #000000;"> nIndex);
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span> Everything_IsFolderResult(<span style="color: #0000ff;">int</span><span style="color: #000000;"> nIndex);
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">bool</span> Everything_IsFileResult(<span style="color: #0000ff;">int</span><span style="color: #000000;"> nIndex);
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span>, CharSet =<span style="color: #000000;"> CharSet.Unicode)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">void</span> Everything_GetResultFullPathNameW(<span style="color: #0000ff;">int</span> nIndex, StringBuilder lpString, <span style="color: #0000ff;">int</span><span style="color: #000000;"> nMaxCount);
    [DllImport(</span><span style="color: #800000;">"</span><span style="color: #800000;">Everything32.dll</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> Everything_Reset();


    </span><span style="color: #0000ff;">#region</span> Enum
    <span style="color: #0000ff;">enum</span><span style="color: #000000;"> StateCode
    {
        OK,
        MemoryError,
        IPCError,
        RegisterClassExError,
        CreateWindowError,
        CreateThreadError,
        InvalidIndexError,
        InvalidCallError
    }
    </span><span style="color: #0000ff;">#endregion</span>

    <span style="color: #0000ff;">#region</span> Property

    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> Gets or sets a value indicating whether [match path].
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;value&gt;&lt;c&gt;</span><span style="color: #008000;">true</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;"> if [match path]; otherwise, </span><span style="color: #808080;">&lt;c&gt;</span><span style="color: #008000;">false</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;">.</span><span style="color: #808080;">&lt;/value&gt;</span>
    <span style="color: #0000ff;">public</span><span style="color: #000000;"> Boolean MatchPath
    {
        </span><span style="color: #0000ff;">get</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> Everything_GetMatchPath();
        }
        </span><span style="color: #0000ff;">set</span><span style="color: #000000;">
        {
            Everything_SetMatchPath(value);
        }
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> Gets or sets a value indicating whether [match case].
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;value&gt;&lt;c&gt;</span><span style="color: #008000;">true</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;"> if [match case]; otherwise, </span><span style="color: #808080;">&lt;c&gt;</span><span style="color: #008000;">false</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;">.</span><span style="color: #808080;">&lt;/value&gt;</span>
    <span style="color: #0000ff;">public</span><span style="color: #000000;"> Boolean MatchCase
    {
        </span><span style="color: #0000ff;">get</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> Everything_GetMatchCase();
        }
        </span><span style="color: #0000ff;">set</span><span style="color: #000000;">
        {
            Everything_SetMatchCase(value);
        }
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> Gets or sets a value indicating whether [match whole word].
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;value&gt;&lt;c&gt;</span><span style="color: #008000;">true</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;"> if [match whole word]; otherwise, </span><span style="color: #808080;">&lt;c&gt;</span><span style="color: #008000;">false</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;">.</span><span style="color: #808080;">&lt;/value&gt;</span>
    <span style="color: #0000ff;">public</span><span style="color: #000000;"> Boolean MatchWholeWord
    {
        </span><span style="color: #0000ff;">get</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> Everything_GetMatchWholeWord();
        }
        </span><span style="color: #0000ff;">set</span><span style="color: #000000;">
        {
            Everything_SetMatchWholeWord(value);
        }
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> Gets or sets a value indicating whether [enable regex].
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;value&gt;&lt;c&gt;</span><span style="color: #008000;">true</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;"> if [enable regex]; otherwise, </span><span style="color: #808080;">&lt;c&gt;</span><span style="color: #008000;">false</span><span style="color: #808080;">&lt;/c&gt;</span><span style="color: #008000;">.</span><span style="color: #808080;">&lt;/value&gt;</span>
    <span style="color: #0000ff;">public</span><span style="color: #000000;"> Boolean EnableRegex
    {
        </span><span style="color: #0000ff;">get</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> Everything_GetRegex();
        }
        </span><span style="color: #0000ff;">set</span><span style="color: #000000;">
        {
            Everything_SetRegex(value);
        }
    }
    </span><span style="color: #0000ff;">#endregion</span>


    <span style="color: #0000ff;">#region</span> Public Method
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> Resets this instance.
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> Reset()
    {
        Everything_Reset();
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> Searches the specified key word.
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;param name="keyWord"&gt;</span><span style="color: #008000;">The key word.</span><span style="color: #808080;">&lt;/param&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> IEnumerable&lt;<span style="color: #0000ff;">string</span>&gt; Search(<span style="color: #0000ff;">string</span><span style="color: #000000;"> keyWord)
    {
        </span><span style="color: #0000ff;">return</span> Search(keyWord, <span style="color: #800080;">0</span>, <span style="color: #0000ff;">int</span><span style="color: #000000;">.MaxValue);
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> Searches the specified key word.
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;param name="keyWord"&gt;</span><span style="color: #008000;">The key word.</span><span style="color: #808080;">&lt;/param&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;param name="offset"&gt;</span><span style="color: #008000;">The offset.</span><span style="color: #808080;">&lt;/param&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;param name="maxCount"&gt;</span><span style="color: #008000;">The max count.</span><span style="color: #808080;">&lt;/param&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> IEnumerable&lt;<span style="color: #0000ff;">string</span>&gt; Search(<span style="color: #0000ff;">string</span> keyWord, <span style="color: #0000ff;">int</span> offset, <span style="color: #0000ff;">int</span><span style="color: #000000;"> maxCount)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">string</span><span style="color: #000000;">.IsNullOrEmpty(keyWord))
            </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> ArgumentNullException(<span style="color: #800000;">"</span><span style="color: #800000;">keyWord</span><span style="color: #800000;">"</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (offset &lt; <span style="color: #800080;">0</span><span style="color: #000000;">)
            </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> ArgumentOutOfRangeException(<span style="color: #800000;">"</span><span style="color: #800000;">offset</span><span style="color: #800000;">"</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (maxCount &lt; <span style="color: #800080;">0</span><span style="color: #000000;">)
            </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> ArgumentOutOfRangeException(<span style="color: #800000;">"</span><span style="color: #800000;">maxCount</span><span style="color: #800000;">"</span><span style="color: #000000;">);

        Everything_SetSearchW(keyWord);
        Everything_SetOffset(offset);
        Everything_SetMax(maxCount);
        </span><span style="color: #0000ff;">if</span> (!Everything_QueryW(<span style="color: #0000ff;">true</span><span style="color: #000000;">))
        {
            </span><span style="color: #0000ff;">switch</span><span style="color: #000000;"> (Everything_GetLastError())
            {
                </span><span style="color: #0000ff;">case</span> (<span style="color: #0000ff;">int</span><span style="color: #000000;">)StateCode.CreateThreadError:
                    </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> CreateThreadException();
                </span><span style="color: #0000ff;">case</span> (<span style="color: #0000ff;">int</span><span style="color: #000000;">)StateCode.CreateWindowError:
                    </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> CreateWindowException();
                </span><span style="color: #0000ff;">case</span> (<span style="color: #0000ff;">int</span><span style="color: #000000;">)StateCode.InvalidCallError:
                    </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> InvalidCallException();
                </span><span style="color: #0000ff;">case</span> (<span style="color: #0000ff;">int</span><span style="color: #000000;">)StateCode.InvalidIndexError:
                    </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> InvalidIndexException();
                </span><span style="color: #0000ff;">case</span> (<span style="color: #0000ff;">int</span><span style="color: #000000;">)StateCode.IPCError:
                    </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> IPCErrorException();
                </span><span style="color: #0000ff;">case</span> (<span style="color: #0000ff;">int</span><span style="color: #000000;">)StateCode.MemoryError:
                    </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> MemoryErrorException();
                </span><span style="color: #0000ff;">case</span> (<span style="color: #0000ff;">int</span><span style="color: #000000;">)StateCode.RegisterClassExError:
                    </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span><span style="color: #000000;"> RegisterClassExException();
            }
            </span><span style="color: #0000ff;">yield</span> <span style="color: #0000ff;">break</span><span style="color: #000000;">;
        }

        </span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> bufferSize = <span style="color: #800080;">256</span><span style="color: #000000;">;
        StringBuilder buffer </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> StringBuilder(bufferSize);
        </span><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> idx = <span style="color: #800080;">0</span>; idx &lt; Everything_GetNumResults(); ++<span style="color: #000000;">idx)
        {
            Everything_GetResultFullPathNameW(idx, buffer, bufferSize);
            </span><span style="color: #0000ff;">yield</span> <span style="color: #0000ff;">return</span><span style="color: #000000;"> buffer.ToString();
        }
    }
    </span><span style="color: #0000ff;">#endregion</span>


    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span>  <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> MemoryErrorException : ApplicationException
    {
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span>  <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> IPCErrorException : ApplicationException
    {
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span>  <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> RegisterClassExException : ApplicationException
    {
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span>  <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> CreateWindowException : ApplicationException
    {
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span>  <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> CreateThreadException : ApplicationException
    {
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span>  <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> InvalidIndexException : ApplicationException
    {
    }

    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span>  <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> InvalidCallException : ApplicationException
    {
    }


    </span><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span><span style="color: #000000;">[] args)
    {
        </span><span style="color: #008000;">//</span><span style="color: #008000;">@"\\10.10.1.10\文件夹名称 &lt;*.png|jpg|bmp&gt;"  或"c:&lt;*.png|jpg|bmp&gt;  dm:2019/5-2019/12为一个时间段内的文件</span>
        <span style="color: #0000ff;">var</span> list = Search(<span style="color: #800000;">@"</span><span style="color: #800000;">文件名或目录</span><span style="color: #800000;">"</span><span style="color: #000000;">);
        ArrayList array </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ArrayList();
        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #0000ff;">var</span> item <span style="color: #0000ff;">in</span><span style="color: #000000;"> list)
        {
            array.Add(item);
        }
    }</span></pre> 

返回的结果就是你要上传的文件列表,如果有需要可以根据自己的需求在次拓展。

原文链接:https://www.cnblogs.com/peter1/p/11177386.html

全部评论: 0

    我有话说: