- 发行说明
- 入门指南
- 教程
- 自动化项目
- 创建自动化
- 故障排除
教程:将文件夹中文件的相关信息添加到 Excel 文件
在本教程中,我们将创建一个自动化方法,该方法可检索文件夹中所有文件的名称和大小,并将此信息添加到 Excel 文件中。
我们将创建一个项目,首先添加一个“使用 Excel 文件”活动,以指明要使用的 Excel 文件。然后,我们将添加一个遍历文件夹中的文件活动,指明要从中检索文件信息的文件夹。在“遍历文件夹中的文件”中,我们将添加两个写入单元格活动,这两个活动会分别将每个文件的名称和大小复制到项目笔记本的两个单元格中。最后,我们将添加一个附加范围活动,在为每个文件填充单元格后,该活动会将两个单元格附加到 Excel 文件的范围中。
-
第 1 步:建立一个项目,并在项目文件夹中创建一个 Excel 文件。
- Create a new blank project using the default settings.
- 在项目文件夹中创建一个 Excel 文件,并将其命名为 files.xlsx。
- 在 Excel 中打开新创建的文件,然后在单元格 A1 中输入文本
File Name,并在单元格 B1 中输入文本File Size。 - 保存并关闭 files.xlsx。
-
第 2 步:将 Excel 文件添加到项目中,并指明要迭代访问的文件所在的文件夹。
-
在 StudioX 的“活动”面板中,选择“Excel”选项卡,然后双击“使用 Excel 文件”。“使用 Excel 文件”活动随即添加到“设计器”面板中。
-
在“使用 Excel 文件”活动中:
- Click Browse
next to the Excel file field, and then browse to and select the file files.xlsx. - 在“引用为”字段中,输入
FilesSizes。
- Click Browse
-
在“活动”面板中,选择“文件”选项卡,然后将“遍历文件夹中的文件”活动拖放到“使用 Excel 文件”活动中。
-
In the For Each File in Folder activity, click Browse
next to the Folder field, and then browse to and select a folder on your computer which contains files, for example the Desktop.
-
-
第 3 步:将有关文件的信息复制到 Excel 文件中。
-
在“活动”面板中,选择“Excel”选项卡,然后将“写入单元格”活动拖放到“遍历文件夹中的文件”中。
-
在“写入单元格”活动中:
- Click Plus
on the right side of the What to write field, and then select CurrentFile > Name to indicate that we want to copy the name of the current file in the iteration. - Click Plus
on the right side of the Where to write field, and then select Project Notebook (Notes) > Indicate in Excel to open the Project Notebook. In the file, select the A1 cell in the Scratchpad sheet, and click Confirm in the UiPath tab in the Excel ribbon. You have indicated that you want to paste the name of the current file in the iteration to cell A1 in the Scratchpad sheet of the Project Notebook.
- Click Plus
-
在第一个活动下面添加第二个“写入单元格”活动。
-
在“写入单元格”活动中:
- Click Plus
on the right side of the What to write field, and then select CurrentFile > Size to indicate that we want to copy the size (in bytes) of the current file in the iteration. - Click Plus
on the right side of the Where to write field, and then select Project Notebook (Notes) > Indicate in Excel to open the Project Notebook. In the file, select the B1 cell in the Scratchpad sheet, and click Confirm in the UiPath tab in the Excel ribbon. You have indicated that you want to paste the size of the current file in the iteration to cell B1 in the Scratchpad sheet of the FilesSizes Excel file.
- Click Plus
-
要使两个“写入单元格”活动更容易识别,请在每个活动的上部栏中编辑名称。例如第一个活动使用
Write Cell Name,第二个活动使用Write Cell Size。 -
在“活动”面板中,将“附加范围”活动拖放到第二个“写入单元格”活动下方的“遍历文件夹中的文件”中。
-
在“附加范围”活动中:
-
Click Plus
on the right side of the Append after range field and then select FilesSizes > Sheet1. -
Click Plus
on the right side of the What to append field, and then select Project Notebook (Notes) > Indicate in Excel to open the file in Excel. In the file, select the A1:B1 cells and click Confirm in the UiPath tab in the Excel ribbon. You have indicated that you want to add the information about the current file in the iteration to columns A and B in the FilesSizes file after the existing data in the file.
-
-
在 StudioX 功能区中单击“保存”,以保存自动化,然后单击“运行”来执行此自动化。
指定文件夹中每个文件的名称和大小将一一复制到项目笔记本的 Scratchpad 工作表中的单元格 A1 和 A2,然后附加到 files.xlsx。
-