4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【UiPath】ファイルのプロパティの詳細確認方法

Last updated at Posted at 2024-01-11

ファイルのプロパティの内容をチェックしたいことありませんか?

UiPathの標準アクティビティの「ファイル情報を取得」では、プロパティの詳細までは確認できません。
今回、Microsoft の WindowsAPICode.Shell パッケージの ShellFile クラスをもちいて確認ができたので、備忘までに記事化します。

パッケージのインストール

※Studio の「パッケージを管理」で検索してヒットする場合は、3番の手順のみで結構です。

  1. 「Microsoft-WindowsAPICodePack-Shell」パッケージを Microsoft の nuget.org からダウンロードします。https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-Shell/
  2. Studio のバックステージビュー>設定>パッケージソースを管理で有効なパッケージソースのフィードまたはフォルダに取得した「Microsoft-WindowsAPICodePack-Shell」パッケージ(microsoft-windowsapicodepack-shell.X.X.X.nupkg)を配置します。
  3. Studio のデザインリボンの「パッケージを管理」より「Microsoft.WindowsAPICodePack.Shell」パッケージをインストールします。

image.png

実装サンプル

  1. ShellObject 型の変数を用意します。(Microsoft.WindowsAPICodePack.Shell.ShellObject
    「代入」アクティビティを配置し、左辺と右辺を次の様に指定します。       左辺:1で作成した変数 右辺: Microsoft.WindowsAPICodePack.Shell.ShellFile.FromParsingName(“{★ファイルパス}”)
  2. 「繰り返し(コレクションの各要素)」を配置し、項目のリストに「{1で作成した変数}.Properties.DefaultPropertyCollection」を指定します。
  3. 「トライ・キャッチ」>「1行を書き込み」を配置し、次の様にしてプロパティの詳細を出力します。
    "CanonicalName:"+currentItem.CanonicalName+" DisplayName:"+currentItem.Description.DisplayName+" PropertyKey:"+currentItem.PropertyKey.ToString+" Value:"+currentItem.ValueAsObject.ToString

image.png

(参考:出力イメージ)
image.png

補足:「Microsoft.WindowsAPICodePack.Shell」パッケージはインストール済みだが、ShellFile クラスが認識されない場合、対象のXamlファイルの名前空間やアセンブリに次の記述があるかご確認ください。(記述が無い場合、手動で追記してください)

名前空間

<x:String>Microsoft.WindowsAPICodePack.Shell</x:String>

アセンブリ設定

<AssemblyReference>Microsoft.WindowsAPICodePack.Shell</AssemblyReference>

※名前空間やアセンブリの設定は Xaml ファイルの最初に記述があります。編集はメモ帳などでおこなえます。

以上 最後までお読みいただきありがとうございます!

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?