UiPath Documentation
studiox
2023.10
false

StudioX user guide

最終更新日時 2026年4月30日

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

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

We will start by adding a File Exists activity to check if the folder where we want to download the attachments already exists. We will then add an If activity and inside it we will add a Create Folder activity to create the folder if it does not exist. If the folder does exist, we will add a Message Box activity to prompt the user to select how to proceed. Another If activity will follow with two separate sets of activities to execute depending on the user's choice - either delete the folder and recreate it or move the existing folder to another location. We will then add the activities to save the attachments from Outlook, and then we will create two folders inside the destination folder, one in which to create the text file with information about the saved files and one in which to move the files after we add the file info to the text file. To add today's date to the folder name, we will use a formula built-in to the Project Notebook.

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

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

  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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD. Click Save in the Text Builder.

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

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

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

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

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

      • [Else を表示] をクリックして、Else 分岐を追加します。
      • Select ドキュメントの画像 Open in Advanced Editor next to the Condition field to open the 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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD. Click Save in the Text Builder.

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

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

    7. Click Plus ドキュメントの画像 on the right side of the Message Box activity, and then select Text. In the Text Builder, enter a message to display to the user, for example:

      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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. Click Save in the Text Builder.

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

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

      • Click Plus ドキュメントの画像 on the right side of the ChosenButton field, then select Save for later use and give a name for the value, for example ChosenButton from Message Box FolderAlreadyExists.

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

        ドキュメントの画像

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

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

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

      • [Else を表示] をクリックして、Else 分岐を追加します。
      • Select ドキュメントの画像 Open in Advanced Editor next to the Condition field to open the 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.

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

      • Click Plus ドキュメントの画像 on the right side of the field on the right, and then select Text. In the Text Builder, enter Yes, and then click Save twice.

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

    4. In the Activities panel, select the File tab, and then drag a Delete Folder activity and drop it inside the Then branch of the second If activity. A Delete Folder activity is added to the Designer panel.

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Notes] 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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD. Click Save in the Text Builder.

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

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

    9. 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:\old_MailAttachments, and then click Save.

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

    10. In the Activities panel, drag a Move Folder activity and drop it inside the Else branch of the second If activity below Create Folder. A Move Folder activity is added to the Designer panel.

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD. Click Save in the Text Builder.

      • Click Plus ドキュメントの画像 on the right side of the To field, and then select Text. In the Text Builder, enter C:\old_MailAttachments, and then click Save.

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

        ドキュメントの画像

  6. Outlook の検索フォルダーから添付ファイルを保存します。

    1. In the Activities panel, select the Mail tab, and then drag a Use Desktop Outlook App and drop it below the first If activity as the last activity in the project. The activity is added to the Designer panel.

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

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

    3. In the Activities panel, drag the For Each Email activity and drop it inside the Use Desktop Outlook App activity.

    4. In the For Each Email activity, click Plus ドキュメントの画像 on the right side of the In emails from field, and then select Outlook > [Search Folders] > [Last week's attachments] to select the search folder created in the account Outlook. Your selection is displayed in the In emails from field as "Last week's attachments".

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

    5. In the Activities panel, drag the Save Email Attachments activity and drop it inside the For Each Email activity.

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD. Click Save in the Text Builder.

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

        ドキュメントの画像

  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 Notebook > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD\Output. Click Save in the Text Builder.

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

    3. In the Activities panel, drag a Create File activity and drop it below the last Create Folder.

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output\AttachmentsDetails.txt. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD\Output\AttachmentsDetails.txt. Click Save in the Text Builder.

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

    5. In the Activities panel, drag a Write Text File activity and drop it below the Create File activity. A Write Text File activity is added to the Designer panel.

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output\AttachmentsDetails.txt. The text should look like this: C:\MailAttachments_[Notes] 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 Notebook > Date [Sheet] > YYYYMMDD [Cell], and then enter \Processed. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD\Processed. Click Save in the Text Builder.

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

      ドキュメントの画像

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

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell]. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD\Output. Click Save in the Text Builder.

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

    3. In the Activities panel, drag an Append Line activity and drop it inside the For Each File in Folder activity. An Append Line activity is added to the Designer panel.

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell], and then enter \Output\AttachmentsDetails.txt. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD\Output\AttachmentsDetails.txt. Click Save in the Text Builder.

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

    5. In the Activities panel, drag a Move File activity and drop it inside the For Each File in Folder activity below Append Line. A Move File activity is added to the Designer panel.

    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 Notebook > Date [Sheet] > YYYYMMDD [Cell], and then enter \Processed. The text should look like this: C:\MailAttachments_[Notes] Date!YYYYMMDD\Processed. Click Save in the Text Builder.

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

        ドキュメントの画像

    7. Click Save in the StudioX ribbon to save the automation, then click Run to execute the automation.The attachments in the Outlook Search Folder are saved to the MailAttachments folder, a text file with information about the files is created in the Output subfolder, and then the files are moved to the Processed subfolder. If you run the project again, because the folder was already created during the first run, you are prompted to select what to do with the existing folder before the other activities are executed. Download example

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

接続

ヘルプ リソース サポート

学習する UiPath アカデミー

質問する UiPath フォーラム

最新情報を取得