右クリックして、参照を選択して、COMタブを選択して、
Microsoft Shell Controls And Automationを追加する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /* 空のCLRプロジェクト 音楽ファイルの長さを取得 */ using namespace System; //Console::ReadLine()で必要 using namespace Shell32; //ShellClass Folder FolderItem とかで必要 [STAThread] //Shell32::Folder ^f = shell->NameSpace(dir);で出る例外対策 void main(){ String ^dir = "G:\\sampleMovie" ; // MP3ファイルのあるディレクトリ String ^file = "Amanda.wma" ; ShellClass ^shell = gcnew ShellClass(); Folder ^f = shell->NameSpace(dir); FolderItem ^item = f->ParseName(file); Console::WriteLine(f->GetDetailsOf(item, 27)); // 長さ win8の場合 Console::ReadLine(); //入力待-ウインドウ維持 } |
すべての属性取得
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /* 空のCLRプロジェクト ファイルの属性をすべて表示・取得 */ #include <stdio.h> //NULL とかで必要 using namespace System; //Console::ReadLine()で必要 using namespace Shell32; //ShellClass Folder FolderItem とかで必要 [STAThread] //Shell32::Folder ^f = shell->NameSpace(dir);で出る例外対策 void main(){ String ^dir = "G:\\sampleMovie" ; // MP3ファイルのあるディレクトリ String ^file = "Amanda.wma" ; ShellClass ^shell = gcnew ShellClass(); Folder ^f = shell->NameSpace(dir); FolderItem ^item = f->ParseName(file); int i = 0; String^ name = f->GetDetailsOf(NULL, i); while ( !String::IsNullOrEmpty( name ) ) { // 属性名 表示 Console::WriteLine( "{0,3} : {1}" , i, name); i++; name = f->GetDetailsOf(NULL, i); } Console::ReadLine(); //入力待-ウインドウ維持 } |
値のある属性のみ取得
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | /* 空のCLRプロジェクト ファイルの属性で値のあるものを表示・取得 */ #include <stdio.h> //NULL とかで必要 using namespace System; //Console::ReadLine()で必要 using namespace Shell32; //ShellClass Folder FolderItem とかで必要 [STAThread] //Shell32::Folder ^f = shell->NameSpace(dir);で出る例外対策 void main(){ String ^dir = "G:\\sampleMovie" ; // MP3ファイルのあるディレクトリ String ^file = "Amanda.wma" ; ShellClass ^shell = gcnew ShellClass(); Folder ^f = shell->NameSpace(dir); FolderItem ^item = f->ParseName(file); int i = 0; String^ name = f->GetDetailsOf(NULL, i); while ( !String::IsNullOrEmpty( name ) ) { // 属性の値を取得 String^ value = f->GetDetailsOf(item, i); //値があれば表示 if (!String::IsNullOrEmpty( value )) { Console::WriteLine( "{0,3} : {1}" , i, name); //属性名 Console::WriteLine( "\t{0}" , value); //値 } i++; name = f->GetDetailsOf(NULL, i); } Console::ReadLine(); //入力待-ウインドウ維持 } |
0 件のコメント:
コメントを投稿