Last active
August 29, 2015 14:01
-
-
Save LilinYume/21a7a8ba660781272eac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.IO; | |
using System.Security; | |
namespace CopyTo | |
{ | |
class Run | |
{ | |
static void Main( ) | |
{ | |
} | |
} | |
enum STATUS { NOT_EXIST, EXIST_FILE, EXIST_FOLDER } | |
class dir | |
{ | |
private string _path; | |
/* フィールド変数の初期値設定 (コンストラクタ) */ | |
public dir() | |
{ | |
_path = string.Empty; | |
} | |
/* 引数に指定した文字列でフィールド変数にパスを設定 (コンストラクタ・オーバーロード) */ | |
public dir( string set_def ) | |
{ | |
error_check( set_def ); | |
_path = set_def; | |
} | |
/* フィールド変数 path (string) への値の設定を促す | |
* 存在するパスであるかのチェックはなし (ユーティリティ) */ | |
public string input_prompt( string messeage ) | |
{ | |
string inpt = string.Empty; | |
Console.Write( messeage ); | |
inpt = Console.ReadLine( ); | |
error_check( inpt ); | |
this._path = inpt; | |
return inpt; | |
} | |
/* 引数でパスを設定 | |
* 引数の値はフィールド変数へ格納する。 (ユーティリティ) */ | |
public void set_path( string path ) | |
{ | |
error_check( path ); | |
this._path = path; | |
} | |
/* ファイル/フォルダパスとして存在する、存在しないかをコンソールに表示 | |
* (ユーティリティ) */ | |
public void view_status() | |
{ | |
if ( string.IsNullOrEmpty( this._path ) == true ) { | |
Console.WriteLine( "Path string is empty " ); | |
return; | |
} | |
switch ( is_exist( this._path ) ) { | |
case STATUS.NOT_EXIST: | |
Console.WriteLine( "Useless path" ); | |
break; | |
case STATUS.EXIST_FILE: | |
Console.WriteLine( "Path is exist as FILE" ); | |
break; | |
case STATUS.EXIST_FOLDER: | |
Console.WriteLine( "Path is exist as DIRECTORY" ); | |
break; | |
} | |
} | |
/* 存在するファイル/ディレクトリ パスかを調べる | |
* フィールド変数 path (string) 内の値がファイル・パスとして存在するか | |
* フィールド変数 path (string) 内の値がディレクトリ・パスとして存在するか | |
* 戻り値として返すのは状態を表す列挙体を返す。 (ヘルパ) */ | |
protected STATUS is_exist( string check_path ) | |
{ | |
STATUS code = 0; | |
bool exist_file, exist_folder; | |
exist_folder = Directory.Exists( check_path ); | |
exist_file = File.Exists( check_path ); | |
if ( exist_folder == false && exist_file ) code = STATUS.NOT_EXIST; | |
if ( exist_file == true ) code = STATUS.EXIST_FILE; | |
if ( exist_folder == true ) code = STATUS.EXIST_FOLDER; | |
return code; | |
} | |
/* エラーチェック | |
* パスとして妥当な文字列表現かを試す。 | |
* 存在するファイル/フォルダ パスかどうかはチェックしない。 (ヘルパ) */ | |
protected void error_check( string target ) | |
{ | |
try { | |
Path.GetFullPath( target ); | |
} | |
catch ( ArgumentException arg_err ) { | |
Console.Error.WriteLine( "Err: " + arg_err.Message ); | |
} | |
catch ( SecurityException access_err ) { | |
Console.Error.WriteLine( "Err: " + access_err.Message ); | |
} | |
catch ( NotSupportedException valid_err ) { | |
Console.Error.WriteLine( "Err: " + valid_err.Message ); | |
} | |
catch ( PathTooLongException len_err ) { | |
Console.Error.WriteLine( "Err: " + len_err.Message ); | |
} | |
} | |
/* フィールド変数 path (string) にアクセスするプロパティ (アクセス) */ | |
public string get_path | |
{ | |
get { return this._path; } | |
private set { ;} | |
} | |
} | |
/* よく使いそうなパスをプリセットしておく */ | |
static class Libs | |
{ | |
public static string MyDoc | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments ); } | |
} | |
public static string MyPic | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.MyPictures ); } | |
} | |
public static string MyMus | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.MyMusic ); } | |
} | |
public static string MyVid | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.MyVideos ); } | |
} | |
public static string MyCom | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ); } | |
} | |
public static string MyHome | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.Personal ); } | |
} | |
public static string MyDesk | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory ); } | |
} | |
} | |
/* よく使いそうなパスをプリセットしておく */ | |
static class MyPc | |
{ | |
public static string MyPgm | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.ProgramFiles ); } | |
} | |
public static string MyPgm86 | |
{ | |
get { return Environment.GetFolderPath( Environment.SpecialFolder.ProgramFilesX86 ); } | |
} | |
public static string[] MyPVolume | |
{ | |
get { return Environment.GetLogicalDrives( ); } | |
} | |
} | |
class seek_dir : dir | |
{ | |
public seek_dir() : base() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment