いろいろ試行錯誤

調べものしたときの覚書きや、仕事でコーディングした時のメモ などなど…

テキストファイルから重複行+NGワード削除≪Hashtable編≫

try
{
    StreamReader sr = null;
    string s;
    Hashtable ngHash = new Hashtable();
    //NGデータのHashtable作成
    try
    {
        sr = new StreamReader(@"C:\temp\ngdata.txt", Encoding.GetEncoding(932));
        while ((s = sr.ReadLine()) != null) { ngHash[s] = true; }
    }
    finally
    {
        if (sr != null) sr.Close();
    }
    //出力データを作成
    sr = null;
    ArrayList al = new ArrayList();
    try
    {
        sr = new StreamReader(@"C:\temp\data.txt", Encoding.GetEncoding(932)); 
        Hashtable uniqHash = new Hashtable();
        while ((s = sr.ReadLine()) != null)
        {
            if (uniqHash[s] == null)
            {
                uniqHash[s] = true;
                if (ngHash[s] == null) { al.Add(s); }
            }
        }
    }
    finally
    {
        if (sr != null) sr.Close();
    }
    //ソート
    al.Sort();
    //出力
    StreamWriter sw = null;
    try
    {
        sw = new StreamWriter(@"C:\temp\output.txt", false, Encoding.GetEncoding(932));
        for (int i=0; i<al.Count; i++) { sw.WriteLine(al[i]); }
    }
    finally
    {
        if (sw != null) sw.Close();
    }
}
catch(Exception ex)
{
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
}

テキストファイルから重複行削除≪OLEDB編≫

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\;Extended Properties=\"text;HDR=NO;FMT=Delimited\"") ;
            OleDbCommand cmd = new OleDbCommand("select distinct *  from Test.txt", con);
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            int rowcount = 0;
            while (dr.Read() == true)
            {
                rowcount++;
                Console.WriteLine(dr.GetValue(0));
            }
            Console.WriteLine(rowcount);
            con.Close();
        }
    }
}

IISのIUSRとIWAMユーザのパスワードを調べる

'==========================================================
'IISのIUSRとIWAMユーザのパスワードを調べる
'==========================================================
Dim IIsObject
Set IIsObject = GetObject ("IIS://localhost/w3svc")
WScript.Echo "AnonymousUserName = " & IIsObject.Get("AnonymousUserName")
WScript.Echo "AnonymousUserPass = " & IIsObject.Get("AnonymousUserPass")
WScript.Echo "WAMUserName = " & IIsObject.Get("WAMUserName")
WScript.Echo "WAMUserPass = " & IIsObject.Get("WAMUserPass")
Set IIsObject = Nothing

MSDOSからワイルドカード指定で複数ファイル名の一部を一括変更する

#=================================================
#MSDOSからワイルドカード指定で複数ファイル名の一部を一括変更する
# 例)「a.dat.gz」「b.dat.gz」「c.dat.gz」→「a.gz」「b.gz」「c.gz」
#http://oshiete.goo.ne.jp/qa/2928708.html
#=================================================
for /f "usebackq delims=. tokens=1" %i in (`dir /b *.dat.gz`) do echo ren %i.dat.gz %i.gz
for /f "usebackq delims=$ tokens=1" %i in (`dir /b *$.png`) do ren %~ni$.png %~i.png
#-------------------------------------------------

#=================================================
#
#http://www.atmarkit.co.jp/fwin2k/win2ktips/761renext/renext.html
#=================================================
#確認用
for /r /d %i in (*) do echo ren "%i\*.txt" "*.txt2"
#実行用
for /r /d %i in (*) do ren "%i\*.txt" "*.txt2"
#-------------------------------------------------