// ProcessStartInfo の新しいインスタンスを生成する
System.Diagnostics.ProcessStartInfo hPsInfo = (
new System.Diagnostics.ProcessStartInfo()
);
// 起動するアプリケーションを設定する
hPsInfo.FileName = "Notepad";
// コマンドライン引数を設定する
hPsInfo.Arguments = @"C:\Hoge.txt";
// 新しいウィンドウを作成するかどうかを設定する (初期値 false)
hPsInfo.CreateNoWindow = true;
// シェルを使用するかどうか設定する (初期値 true)
hPsInfo.UseShellExecute = false;
// 起動できなかった時にエラーダイアログを表示するかどうかを設定する (初期値 false)
hPsInfo.ErrorDialog = true;
// エラーダイアログを表示するのに必要な親ハンドルを設定する
hPsInfo.ErrorDialogParentHandle = this.Handle;
// アプリケーションを起動する時の動詞を設定する
hPsInfo.Verb = "Open";
// 起動ディレクトリを設定する
hPsInfo.WorkingDirectory = @"C:\Hoge\";
// 起動時のウィンドウの状態を設定する
hPsInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; //通常
hPsInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //非表示
hPsInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized; //最小化
hPsInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized; //最大化
// ProcessStartInfo を指定して起動する
System.Diagnostics.Process.Start(hPsInfo);
2011年3月9日水曜日
2011年3月8日火曜日
C# ファイルのパスを調べる関係
if (File.Exists(filePath)) {
// filePathのファイルは存在する
} else {
// filePathのファイルは存在しない
}
if (Directory.Exists(dirPath)) {
// dirPathのディレクトリは存在する
} else {
// dirPathのディレクトリは存在しない
}
//ファイルのサイズを取得
System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\test.txt");
long filesize = fi.Length;
// パスを定数で定義する
const string FILE_PATH = @"C:\Hoge.txt";
// 作成日時を取得する
DateTime dtCreate = System.IO.File.GetCreationTime(FILE_PATH);
// 更新日時を取得する
DateTime dtUpdate = System.IO.File.GetLastWriteTime(FILE_PATH);
// アクセス日時を取得する
DateTime dtAccess = System.IO.File.GetLastAccessTime(FILE_PATH);
// 取得したタイムスタンプを表示する
MessageBox.Show("作成日時 : " + dtCreate.ToString());
MessageBox.Show("更新日時 : " + dtUpdate.ToString());
MessageBox.Show("アクセス日時 : " + dtAccess.ToString());
// filePathのファイルは存在する
} else {
// filePathのファイルは存在しない
}
if (Directory.Exists(dirPath)) {
// dirPathのディレクトリは存在する
} else {
// dirPathのディレクトリは存在しない
}
//ファイルのサイズを取得
System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\test.txt");
long filesize = fi.Length;
// パスを定数で定義する
const string FILE_PATH = @"C:\Hoge.txt";
// 作成日時を取得する
DateTime dtCreate = System.IO.File.GetCreationTime(FILE_PATH);
// 更新日時を取得する
DateTime dtUpdate = System.IO.File.GetLastWriteTime(FILE_PATH);
// アクセス日時を取得する
DateTime dtAccess = System.IO.File.GetLastAccessTime(FILE_PATH);
// 取得したタイムスタンプを表示する
MessageBox.Show("作成日時 : " + dtCreate.ToString());
MessageBox.Show("更新日時 : " + dtUpdate.ToString());
MessageBox.Show("アクセス日時 : " + dtAccess.ToString());
登録:
投稿 (Atom)