// コンパイルしてできたexeファイルのアイコンの上に、フォルダまたはファイルを // ドロップします(記述やSendtoでも可能です)。すると、droptarget_02.logという // ログファイルが毎度作成されます。さらに、引数をコンソールで通知します。 // ログはストリームライターを使い、sw.WriteLine("hoge");などで書き込み可能です。 // 引数はargs[0]で受け取られ、target[0]へ値渡しされています。 using System; using System.IO; using System.Text; namespace droptorun_01b { class Program { static void Main(string[] args) { string FILE_NAME = "droptorun_01.log"; // D&D時にカレントディレクトリがexeのある場所からD&Dしたディレクトリの // 場所(D&Dしたディレクトリの指す場所のひとつ上)に変更されてしまう。 // そのカレントディレクトリをexeの場所を示すようにセットし直す。 Console.WriteLine("現在のカレントディレクトリは\n\"{0}\"", Directory.GetCurrentDirectory()); string execurrentDir = Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location); // exeの場所を得る1 // 得たexeファイルの場所(execurrentDir)をカレントディレクトリにセットし直す Directory.SetCurrentDirectory(execurrentDir); Console.WriteLine("カレントディレクトリをセットし直しました."); Console.WriteLine("カレントディレクトリ ~ \n\"{0}\"\n", Directory.GetCurrentDirectory()); string execurrentDir2 = System.AppDomain.CurrentDomain.BaseDirectory; // exeの場所を得る2 string[] target; target = new string[1]; // 引数の処理 if (args.Length == 0) { Console.WriteLine("引数はありません"); } else { target[0] = args[0]; Console.WriteLine("引数があります. \"{0}\"です.", target[0]); //Console.Beep(); } // ログファイル(FILE_NAME)の処理 if (File.Exists(FILE_NAME)) { Console.WriteLine("ログファイル(" + FILE_NAME + ")がすでにあります. 一度削除します."); File.Delete(FILE_NAME); Console.WriteLine("ログファイルを消しました."); } else Console.WriteLine("ログファイルがありません. 作成します."); Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS"); using (StreamWriter sw = new StreamWriter(@FILE_NAME, false, sjisEnc)) { sw.WriteLine(DateTime.Now); Console.WriteLine("ログファイル(" + FILE_NAME + ")を作って日付(" + DateTime.Now + ")を書き込みました."); } Console.WriteLine("Press Any Key to End..."); Console.ReadKey(); } } } // 2016H28/05/18 WED 18:14 /* C#でカレントディレクトリの取得方法について - C・C++ 解決済 | 教えて!goo http://oshiete.goo.ne.jp/qa/8035501.html string execurrentDir = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location); string execurrentDir2 = System.AppDomain.CurrentDomain.BaseDirectory; 作業フォルダのパスを取得/設定するには?[C#、VB] - @IT http://www.atmarkit.co.jp/fdotnet/dotnettips/852currentdir/currentdir.html System.IO.Directory.SetCurrentDirectory */ // 2016H28/05/24 TUE 18:56 // このページは、Notepad++により作成されています. // [プラグイン] - [NppExport] - [Export to HTML]でHTML作成しています. //