UiPath Documentation
studiox
2021.10
false
StudioX ユーザー ガイド
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。

チュートリアル: ファイルとフォルダーを操作する

このチュートリアルでは、Outlook 検索フォルダーのすべてのメールの添付ファイルをフォルダーに保存し、フォルダーに今日の日付を含む名前を付けて、すべてのファイル名がコピーされているテキスト ファイルを作成するオートメーションを作成します。このオートメーションは、最初にファイルを保存するフォルダーが既に存在するかどうかを確認し、存在する場合は、フォルダーを削除して再作成する必要があるか、または添付ファイルをダウンロードする前にフォルダーの内容を別のフォルダーに移動する必要があるかをユーザーにたずねます。

最初に、添付ファイルのダウンロード先フォルダーが既に存在するかどうかを確認するために、[ ファイルの存在 を確認] アクティビティを追加します。次に、[ 条件分岐 (if )] アクティビティを追加して、その内部に、フォルダーが存在しない場合にフォルダーを作成する [フォルダーを作成 ] アクティビティを追加します。フォルダーが存在する場合は、どのように処理を進めるかを選択するようにユーザーに要求する [ メッセージ ボックス ] アクティビティを追加します。次に、[条件分岐 (if)] アクティビティを 1 つ、およびユーザーの選択に応じて実行する一連のアクティビティを 2 セット、すなわちフォルダーを削除して再作成するアクティビティと既存のフォルダーを別の場所に移動するアクティビティを追加します。次に、Outlook から添付ファイルを保存するアクティビティを追加し、保存先フォルダー内に 2 つのフォルダー、すなわち保存したファイルに関する情報が記述されたテキスト ファイルを作成するフォルダーとテキスト ファイルにファイル情報を追加した後にファイルを移動するフォルダーを作成します。フォルダー名に今日の日付を追加するには、プロジェクト ノートブックに組み込まれている式を使用します。

  1. 手順 1: Outlook に検索フォルダーを作成する

    1. Outlook を開き、[フォルダー] ペインで [検索フォルダー] を右クリックし、[新しい検索フォルダー] を選択します。
    2. [新しい検索フォルダー] ウィンドウで、[カスタム検索フォルダーを作成する] > [選択] を選択します。
    3. [検索フォルダーのカスタマイズ] ウィンドウで、[名前] ボックスに「Last week's attachments」と入力し、[条件] を選択します。
    4. [検索フォルダーの条件] ウィンドウの [メッセージ] タブで、[時間の条件] の横にあるドロップダウン メニューから [受信日時][先週] を選択します。
    5. [詳細設定] タブで、[添付ファイル] を選択し、隣接するドロップダウン メニューから 1 つ以上の添付ファイルを選択します。
    6. [OK] を 3 回クリックしてウィンドウを閉じて、検索フォルダーを保存します。
  2. 手順 2: プロジェクトを設定する

  3. 手順 3: 添付ファイルの保存先フォルダーが存在するかどうかを確認する

    1. [アクティビティ] パネルで、[ファイル] タブを選択し、[フォルダーの存在を確認] をダブルクリックします。[フォルダーの存在を確認] アクティビティがデザイナー パネルに追加されます。

    2. [フォルダーの存在を確認] アクティビティで、次のステップを実行します。

      • Click Plusドキュメントの画像 on the right side of the Folder path field, and then select Text. In the Text Builder, enter C:\MailAttachments_, and then, from the Plusドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD. Click Save in the Text Builder.

      • Click Plus ドキュメントの画像 on the right side of the Output field, and then select Save for Later Use. Give the value the name Folder 'MailAttachments' Exists and click OK

        これで、MailAttachments に当日の日付が追加された名前のフォルダーが存在するかどうかを確認し、その確認の出力結果を後でオートメーションで使用するために保存するように指定したことになります。

  4. 手順 4: フォルダーが存在するときと存在しないときに実行するアクティビティをそれぞれ追加する

    1. [アクティビティ] パネルで、[共通] タブを選択し、[条件分岐 (if)] アクティビティをドラッグして [フォルダーの存在を確認] アクティビティの下にドロップします。[条件分岐 (if)] アクティビティがデザイナー パネルに追加されます。

    2. [条件分岐 (if)] アクティビティで、次の操作を行います。

      • [Else を表示] をクリックして、Else 分岐を追加します。
      • Click Plusドキュメントの画像 on the right side of the Condition field, and then select Condition Builder.
    3. [条件ビルダー] で条件「if the folder exists」を追加して、次のステップを実行します。

      • Click Plusドキュメントの画像 on the right side of the field on the left, and then select Use Saved Value > Folder 'MailAttachments' Exists to select the output of the Folder Exists activity as the value to evaluate in the condition.

      • 中央のドロップダウン メニューから [true である] を選択して [保存] をクリックします。

        [条件分岐 (if)] アクティビティの Then 分岐に追加したアクティビティはフォルダーが存在する場合に実行され、Else 分岐に追加したアクティビティはフォルダーが存在しない場合に実行されます。

    4. [アクティビティ] パネルで、[ファイル] タブを選択し、[フォルダーを作成] アクティビティをドラッグして [条件分岐 (if)] アクティビティの Else 分岐内にドロップします。[フォルダーを作成] アクティビティがデザイナー パネルに追加されます。

    5. In the Create Folder activity, click Plus ドキュメントの画像 on the right side of the Folder name field, and then select Text. In the Text Builder, enter C:\MailAttachments_, and then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD. Click Save in the Text Builder.

      これで、フォルダーがまだ存在していない場合は、MailAttachments に当日の日付が追加された名前のフォルダーを作成するように指定したことになります。

    6. [アクティビティ] パネルで、[共通] タブを選択し、[メッセージ ボックス] アクティビティをドラッグして [条件分岐 (if)] アクティビティの Then 分岐内にドロップします。[メッセージ ボックス] アクティビティがデザイナー パネルに追加されます。

    7. [メッセージ ボックス] アクティビティの右側にあるプラス記号 ドキュメントの画像 をクリックし、[テキスト] を選択します。テキスト ビルダーでユーザーに表示するメッセージを入力します。例:

      An older MailAttachments_ folder already exists. Do you want to delete the old one and create a new one? If you choose "No", the old one will be moved to a backup folder and a new one will be created.. To add the current date to the folder name, place the mouse cursor after MailAttachments_, and then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. Click Save in the Text Builder.

    8. デザイナー パネルに追加した [メッセージ ボックス] アクティビティを選択し、[プロパティ] パネルを開きます。

      • [ボタン] ドロップダウン メニューから [YESNo] を選択します。

      • ドキュメントの画像[ChosenButton from Message Box FolderAlreadyExists 選択されたボタン] フィールドの右側にある プラス 記号 をクリックし、[ 後で使用するために保存] を選択します。そして、たとえば [] など、値に名前を付けます。

        これで、フォルダーが既に存在する場合に [はい] と [いいえ] の 2 つのボタン オプションがあるメッセージ ボックスを表示して、フォルダーを削除する必要があるかどうかをユーザーに選択させるように指定したことになります。ユーザーの選択内容は、後でオートメーションで使用するために保存されます。

  5. 手順 5: 同じ名前の既存のフォルダーを削除または移動することをユーザーが選択した場合に実行するアクティビティを追加する

    1. [アクティビティ] パネルで、[共通] タブを選択し、2 番目の [条件分岐 (if)] アクティビティをドラッグして 1 番目の [条件分岐 (if)] アクティビティの [Then] 分岐内の [メッセージ ボックス] の下にドロップします。[条件分岐 (if)] アクティビティがデザイナー パネルに追加されます。

    2. [条件分岐 (if)] アクティビティで、次の操作を行います。

      • [Else を表示] をクリックして、Else 分岐を追加します。
      • Click Plusドキュメントの画像 on the right side of the Condition field, and then select Condition Builder.
    3. 条件ビルダーで条件「if the user clicked Yes」を追加します。次の操作を行います。

      • Click Plusドキュメントの画像 on the right side of the field on the left, and then select Use Saved Value > ChosenButton from Message Box FolderAlreadyExists. This selects the user's choice (the button clicked in the Message Box activity) as the value to evaluate in the condition.

      • 中央のドロップダウン メニューから、[等しい] を選択します。

      • 右側にある フィールドの右側にあるプラス記号 ドキュメントの画像 をクリックし、[ テキスト] を選択します。テキスト ビルダーに「 Yes」と入力して、[ 保存 ] を 2 回クリックします。

        [条件分岐 (if)] アクティビティの Then 分岐に追加したアクティビティはユーザーが [はい] をクリックした場合に実行され、Else 分岐に追加したアクティビティはユーザーが [いいえ] をクリックした場合に実行されます。

    4. [ アクティビティ ] パネルで、[ ファイル ] タブを選択し、[ フォルダーを削除] アクティビティをドラッグして 2 番目の [条件分岐 (if)] アクティビティの Then 分岐内にドロップします。[フォルダーを削除] アクティビティがデザイナー パネルに追加されます。

    5. In the Delete Folder activity, click Plus ドキュメントの画像 on the right side of the Folder name field, and then select Text. In the Text Builder, enter C:\MailAttachments_, and then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD. Click Save in the Text Builder.

      これで、MailAttachments に当日の日付が追加された名前の既存のフォルダーを削除するように指定したことになります。

    6. [アクティビティ] パネルで、[フォルダーを作成] アクティビティをドラッグして 2 番目の [条件分岐 (if)] アクティビティの [Then] 分岐内の [フォルダーを削除] の下にドロップします。[フォルダーを作成] アクティビティがデザイナー パネルに追加されます。

    7. In the Create Folder activity, click Plus ドキュメントの画像 on the right side of the Folder name field, and then select Text. In the Text Builder, enter C:\MailAttachments_, and then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD. Click Save in the Text Builder.

      これで、MailAttachments に当日の日付が追加された名前の新しいフォルダーを作成するように指定したことになります。

    8. [アクティビティ] パネルで、[フォルダーを作成] アクティビティをドラッグして 2 番目の [条件分岐 (if)] アクティビティの Else 分岐内にドロップします。[フォルダーを作成] アクティビティがデザイナー パネルに追加されます。

    9. [フォルダーを作成] アクティビティで、[ドキュメントの画像 フォルダー名] フィールドの右側にある プラス 記号 をクリックし、[ テキスト] を選択します。テキスト ビルダーに「 C:\old_MailAttachments」と入力して [ 保存] をクリックします。

      これで、old_MailAttachments という名前の新しいフォルダーを作成するように指定したことになります。

    10. [ アクティビティ ] パネルで、[ フォルダーを移動 ] アクティビティをドラッグして 2 番目の [条件分岐 (if)] アクティビティの [Else] 分岐内の [フォルダーを作成] アクティビティの下にドロップします。[フォルダーを作成] アクティビティがデザイナー パネルに追加されます。

    11. [フォルダーを移動] アクティビティで、次の操作を行います。

      • Click Plusドキュメントの画像 on the right side of the From field, and then select Text. In the Text Builder, enter C:\MailAttachments_, and then, from the Plusドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD. Click Save in the Text Builder.

      • [ドキュメントの画像 宛先] フィールドの右側にある プラス 記号 をクリックし、[ テキスト] を選択します。テキスト ビルダーに「 C:\old_MailAttachments」と入力して [ 保存] をクリックします。

        これで、MailAttachments に当日の日付が追加された名前の既存のフォルダーをフォルダー old_MailAttachments に移動するように指定したことになります。

  6. 手順 6: Outlook 検索フォルダーから添付ファイルを保存する

    1. [アクティビティ] パネルで [ メール ] タブを選択し、[ デスクトップ版 Outlook アプリを使用 ] をドラッグして 1 番目の [条件分岐 (if)] アクティビティの下にプロジェクトの最後のアクティビティとしてドロップします。アクティビティがデザイナー パネルに追加されます。

    2. このアクティビティの [アカウント] フィールドには、あらかじめ既定のメール アカウントが入力されています。別のアカウントを使用する場合は、ドロップダウン メニューから選択します。

      [参照名] フィールドは既定値 Outlook のままとして、オートメーションでアカウントを参照するときは、この名前を使用します。

    3. [アクティビティ] パネルで [繰り返し (各メール)] アクティビティをドラッグし、[デスクトップ版 Outlook アプリを使用] アクティビティ内にドロップします。

    4. [繰り返し (各メール)]ドキュメントの画像 アクティビティで、[ 対象フォルダー] フィールドの右側にある プラス 記号 をクリックし、[ Outlook >[フォルダーを検索] > [Last week's attachments] を選択して、アカウントOutlook に作成した検索フォルダーを選択します。選択は [ 対象フォルダー ] フィールドに「Last week's attachments」と表示されます。

      これで、検索フォルダーの [Last week's attachments] のメールを反復処理するように指定したことになります。

    5. [アクティビティ] パネルで、[ メールの添付ファイルを保存 ] アクティビティをドラッグして、[ 繰り返し (各メール )] アクティビティ内にドロップします。

    6. [メールの添付ファイルを保存] アクティビティで、次の操作を行います。

      • Click Plusドキュメントの画像 on the right side of the From message field, and then select CurrentMail to indicate that the email whose attachments you want to save is the current email you are iterating through.

      • Click Plus ドキュメントの画像 on the right side of the Save to folder field, and then select Text. In the Text Builder, enter C:\MailAttachments_, and then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD. Click Save in the Text Builder.

        これで、MailAttachments に当日の日付が追加された名前のフォルダーに添付ファイルを保存するように指定したことになります。

  7. 手順 7: ファイルに関する情報を追加するテキスト ファイルを作成し、テキスト ファイルの保存先かつ添付ファイルの移動先のサブフォルダーを作成する

    1. [アクティビティ] パネルで、[ファイル] タブを選択し、[フォルダーを作成] アクティビティをドラッグして [デスクトップ版 Outlook アプリを使用] の下にプロジェクトの最後のアクティビティとしてドロップします。[フォルダーを作成] アクティビティがデザイナー パネルに追加されます。

    2. In the Create Folder activity, click Plus ドキュメントの画像 on the right side of the Folder name field, and then select Text. In the Text Builder, enter C:\MailAttachments_, then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD\Output. Click Save in the Text Builder.

      これで、MailAttachments フォルダーに Output という名前のサブフォルダーを作成するように指定したことになります。

    3. [ アクティビティ ] パネルで、[ ファイルを作成] アクティビティをドラッグして、最後の [フォルダーを作成] の下にドロップします。

    4. In the Create File activity, click Plus ドキュメントの画像 on the right side of the File location field, and then select Text. In the Text Builder, enter C:\MailAttachments_, then, from the Plus ドキュメントの画像 menu on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output\AttachmentsDetails.txt. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD\Output\AttachmentsDetails.txt. Click Save in the Text Builder.

      これで、Output サブフォルダーに AttachmentsDetails.txt という名前のファイルを作成するように指定したことになります。

    5. [ アクティビティ ] パネルで、[ テキスト ファイルに書き込み ] アクティビティをドラッグして、[ファイルを作成] アクティビティの下にドロップします。[テキスト ファイルに書き込み] アクティビティがデザイナー パネルに追加されます。

    6. [テキスト ファイルに書き込み] アクティビティで、次のステップを実行します。

      • Click Plusドキュメントの画像 on the right side of the Text field, and then select Text. In the Text Builder, enter Files received in the last week:. Click Save in the Text Builder.

      • Click Plus ドキュメントの画像 on the right side of the Write to filename field, and then select Text. In the Text Builder, enter C:\MailAttachments_, then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output\AttachmentsDetails.txt. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD\Output\AttachmentsDetails.txt. Click Save in the Text Builder.

        これで、ファイル AttachmentsDetails.txt にテキスト「Files received in the last week:」を書き込むように指定したことになります。

    7. [アクティビティ] パネルで、[フォルダーを作成] アクティビティをドラッグして、[テキスト ファイルに書き込み] アクティビティの下にドロップします。[フォルダーを作成] アクティビティがデザイナー パネルに追加されます。

    8. In the Create Folder activity, click Plus ドキュメントの画像 on the right side of the Folder name field, and then select Text. In the Text Builder, enter C:\MailAttachments_, then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell], and then enter \Processed. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD\Processed. Click Save in the Text Builder.

      これで、MailAttachments フォルダーに Processed という名前のサブフォルダーを作成するように指定したことになります。

  8. 手順 8: ファイルを反復処理して、各ファイルに関する情報をテキスト ファイルに追加し、各ファイルを Processed サブフォルダーに移動する

    Outlook 検索フォルダーの添付ファイルが MailAttachments フォルダーに保存され、保存されたファイルに関する情報が書き込まれたテキスト ファイルが Output サブフォルダーに作成され、保存されたファイルが Processed サブフォルダーに移動されます。プロジェクトをもう一度実行すると、1 回目の実行中にフォルダーが作成されているので、ユーザーは既存のフォルダーの処理方法を選択するように要求されます。選択した後、他のアクティビティが実行されます。

    1. [アクティビティ] パネルで、[繰り返し (フォルダー内の各ファイル)] アクティビティをドラッグして、最後の [フォルダーを作成] アクティビティの下にドロップします。[繰り返し (フォルダー内の各ファイル)] アクティビティがデザイナー パネルに追加されます。

    2. In the For Each File in Folder activity, click Plus ドキュメントの画像 on the right side of the Folder field, and then select Text. In the Text Builder, enter C:\MailAttachments_, and then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD\Output. Click Save in the Text Builder.

      これで、MailAttachments フォルダーにあるファイルを反復処理するように指定したことになります。

    3. [ アクティビティ ] パネルで、[ 文字列を追加書き込み ] アクティビティをドラッグして、[繰り返し (フォルダー内の各ファイル)] アクティビティ内にドロップします。[文字列を追加書き込み] アクティビティがデザイナー パネルに追加されます。

    4. [文字列を追加書き込み] アクティビティで、次のステップを実行します。

      • Click Plusドキュメントの画像 on the right side of the Text field, and then select Text. In the Text Builder, enter FileName:, then, from the Plusドキュメントの画像 on the right side of the Text Builder, select CurrentFile > Name, then enter | LastModifiedDate:, then, from the Plusドキュメントの画像 on the right side of the Text Builder, select CurrentFile > Last Modified Date . The text should look like this: FileName: [CurrentFile] Name | LastModifiedDate: [CurrentFile] LastModifiedDate. Click Save in the Text Builder.

      • Click Plus ドキュメントの画像 on the right side of the Write to filename field, and then select Text. In the Text Builder, enter C:\MailAttachments_, then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output\AttachmentsDetails.txt. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD\Output\AttachmentsDetails.txt. Click Save in the Text Builder.

        これで、反復処理している現在のファイルのファイル名と最終変更日時をファイル AttachmentsDetails.txt に書き込むように指定したことになります。

    5. [ アクティビティ ] パネルで、[ ファイルを移動 ] アクティビティをドラッグして、[繰り返し (フォルダー内の各ファイル)] アクティビティ内の [文字列を追加書き込み] の下にドロップします。[ファイルを移動] アクティビティがデザイナー パネルに追加されます。

    6. [ファイルを移動] アクティビティで、次の手順を実行します。

      • Click Plusドキュメントの画像 on the right side of the From field, and then select CurrentFile > Full Path.

      • Click Plus ドキュメントの画像 on the right side of the To field, and then select Text, In the Text Builder, enter C:\MailAttachments_, then, from the Plus ドキュメントの画像 on the right side of the Text Builder, select Project Notebook (Notes) > Date [Sheet] > YYYYMMDD [Cell], and then enter \Processed. The text should look like this: C:\MailAttachments_[Excel] Date!YYYYMMDD\Processed. Click Save in the Text Builder.

        これで、反復処理している現在のファイルを Processed サブフォルダーに移動するように指定したことになります。

    7. StudioX のリボンで [保存] をクリックしてオートメーションを保存し、[実行] をクリックしてオートメーションを実行します。

このページは役に立ちましたか?

接続

ヘルプ リソース サポート

学習する UiPath アカデミー

質問する UiPath フォーラム

最新情報を取得