Support Portal

for ProcessRobot and WinAutomation

Start a new topic
Answered

Read random text file from folder?

How can I get all files in a folder, and read from a random file in that folder/store into a list?


Thanks!!!


Best Answer

Please find the steps in screenshot.


  1. First action will get all files in folder and stores in %Files% list variable
  2. Generate Random number between 0 and %Files.Count-1%
  3. Use the Random number as index in Read text from File action.

Really need this please help!

ADMIN

Hello Alec,


You can use action called get files in folder. Please refer the attached screenshot.


I'm looking to get all files in the folder, and only read from 1 of them, but the file it selects has to be random

So lets say i have 5 files, 1.txt , 2.txt , 3.txt 4.txt and 5.txt
I want it to pick a random .txt file out of the 5 files it gets from the folder, read the one file, and thats it

Sorry for the confusion, and I truly appreciated the response!

Sorry to bump this again but yeah I still really need this!

Use the WinAutomation 'Generate Random Number' action to pick a number between 1 and the number of files in your list, (%Files.Count%) in the screenshot example above, and use the number generated to read the file from your list of files.

Considered that too, but the file names are randomly generated so not sure how I would approach that

The 'Get Files in Folder' action will return a list of all the files in the folder that satisfy the match  filtering you provide in the action.

This results in a list files being returned to your script.

You'll use the 'Generate Random Number' action to determine which number file from the list you will chose to process.

This number will be the index to get the actual filename chosen from the list of files.

This seems to perfectly satisfy your requirement to me, so if not, then I'm obviously not understanding your requirement properly.

ADMIN
Answer

Please find the steps in screenshot.


  1. First action will get all files in folder and stores in %Files% list variable
  2. Generate Random number between 0 and %Files.Count-1%
  3. Use the Random number as index in Read text from File action.
Login or Signup to post a comment