指定フォルダパスの配下にサブフォルダがあり、その配下のファイル一覧をlist変数lis_Pathに取得する構文

こんにちは。UiPath Studio EnterPrise版23.4.2ユーザの初心者です。

指定フォルダパスのファイル一覧をlist変数lis_Pathに取得する構文は
lis_Path=System.IO.Directory.GetFiles(指定フォルダパス).ToList
であることを知っておりますが、

指定フォルダパスの配下にサブフォルダがあり、その配下のファイル一覧をlist変数lis_Pathに取得する構文をご存じの方、ご教示ください。

1 Like

Hi @gorby

Use the below expression

Directory.GetFiles("your_folder_path", "*.*", SearchOption.AllDirectories).ToList()

  1. Directory.GetFiles: This is a method from the System.IO namespace that retrieves an array of file names in a specified directory that match a certain search pattern.
  2. “your_folder_path”: Replace this with the actual path of the folder you want to search in. For example, if your folder is located at C:\MyFolder, you would replace “your_folder_path” with “C:\MyFolder”.
  3. .”: This is the search pattern used to match all files. The first * matches any file name, and the second * matches any file extension.
  4. SearchOption.AllDirectories: This parameter makes sure that files from all subdirectories are included in the search. This is necessary to get files from subfolders as well.
  5. .ToList(): This converts the array of file names returned by Directory.GetFiles into a List.

Hope it helps!!

Hi @gorby

Try this:

Assign Activity:
Variable: lis_Path (List<String>)
Value: Directory.GetFiles("specified folder path", "*", SearchOption.AllDirectories).ToList

In this syntax:

  • Replace "specified folder path" with the actual path of the folder you want to search in.
  • "*" is used as the search pattern, which means all files will be included. You can modify this pattern to filter files based on a specific file extension or name pattern.
  • SearchOption.AllDirectories ensures that files from all subdirectories are included.

Hope it helps!!
Regards

@gorby

サブフォルダーからファイルを取得するアクティビティごとに、内部のアクティビティごとに別の 1 つを使用します。

これは、メインフォルダー内に多数のサブフォルダーがある場合に便利です。

またはフォルダーアクティビティ内の各ファイルに使用します

フォルダーオプションでメインフォルダーのパスを直接渡します

cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.