> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-en/action-guides/variables/count.md).

# Count

Count is the action used to count the number of elements in a one-dimensional array (or a data list) and return a numeric value. This action is very useful when you need to check the size of the data before processing or set limits for loops.

Common practical application cases include:

#### 1. Counting the number of lines in a text file

When you need to know how many lines a text file (containing account lists, proxies, articles...) has in total:

* How to do it: Use the action File read all lines to read all lines in the file into a variable list, then use the action Count to count that list. The returned value will be the total number of lines in the file.

#### Practical example: Count the number of Facebook links in the file `D:\2.txt`

Suppose you have a file storing a list of Facebook profile links at the path `D:\2.txt` with a content of 9 lines as follows:

```
https://www.facebook.com/nguyenvana
https://www.facebook.com/leminhc
...
https://www.facebook.com/demo.account99
```

To count the total number of lines and retrieve each link in this file, the script will be configured in 2 steps:

* Step 1: Use the action File read all lines to read the file `D:\2.txt`. The returned result will be stored in an array (list) named `$content`. At this point, the system automatically understands:
  * `$content[0]` = `"https://www.facebook.com/nguyenvana"` (Line 1)
  * `$content[1]` = `"https://www.facebook.com/leminhc"` (Line 2)
  * ...
  * `$content[8]` = `"https://www.facebook.com/demo.account99"` (Line 9)
* Step 2: Use the action Count passing in the array `$content` just read, and name the output variable as `$lineCount`.

After running, the variable `$lineCount` will receive the value of `9`. You can immediately use this variable `$lineCount` as the End parameter for the For loop to automatically open each Facebook profile for interaction.

<figure><img src="/files/a2Y24tm4Q1yT6EsRusv9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/RwPwJqWf4bBiZ6ofbcx3" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/OjcEPF8IdKVYIGeHBYMi" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/xArePk3aNToEyOogoVfn" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/SxSuzlysA0uFjsww4TnE" alt=""><figcaption></figcaption></figure>

#### 2. Counting the number of files in a folder

When you need to check the number of images, videos, or documents present in a folder on your computer:

* How to do it: Use the action Folder get file list to retrieve a list of all files, then use the action Count to know exactly how many files are contained in that folder.

#### Practical example: Count the number of real estate images in the folder `D:\bds\cat bi\`

Suppose you have a folder containing images of real estate at the path `D:\bds\cat bi\` with 3 image files named as follows:

* `1.jpg`
* `2.jpg`
* `3.jpg`

To count how many image files are available for automatic posting, the script will be configured in 2 steps:

* Step 1: Use the action Folder get file list pointing to the folder path `D:\bds\cat bi\`. The system will scan the folder and return an array containing the paths of all files, stored in a variable named `$fileList`. At this point, the array data will automatically be assigned as:
  * `$fileList[0]` = `"D:\bds\cat bi\1.jpg"`
  * `$fileList[1]` = `"D:\bds\cat bi\2.jpg"`
  * `$fileList[2]` = `"D:\bds\cat bi\3.jpg"`
* Step 2: Use the action Count passing in the array `$fileList` just retrieved, and name the output variable as `$totalFiles`.

After running, the variable `$totalFiles` will receive the value of `3`. You can use this result to run conditional blocks (for example: If the folder has more than 0 files, then perform the action to upload images to Facebook/Website).

<figure><img src="/files/5mlxllFp2OsSSpqH7I4K" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/hcVAdgHJ05eBQkzjVUxS" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/XBi59943MWvf335Jt3Qx" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/0PcrzVLYdn3tLUh7d9Yq" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9yFDchGkq9ZNRw2u2q00" alt=""><figcaption></figcaption></figure>

#### 3. Counting the number of elements after splitting a string

When you have a long text string containing a lot of information separated by special characters and want to know how many elements will be after splitting:

* How to do it: After using the action Split text to split this string based on the character `|`, you let the action Count process the split list. The returned count variable will then be `6`.

#### Practical example: Count the number of elements in the string after using Split text

Suppose you have a configuration file or a line of data containing account information formatted with the separator `|` as follows:

```
thanhnguyen|Pass1234|2FAXYZ|103.83.77.15:9898
```

To count how many pieces of information this string has to serve the validation of the account, the script will be configured in 2 steps:

* Step 1: Use the action Split text to split the above string based on the separator character `|`. The returned result will be stored in an array named `$accountData`. At this point, the system will automatically split the data into:
  * `$accountData[0]` = `"thanhnguyen"` (Account)
  * `$accountData[1]` = `"Pass1234"` (Password)
  * `$accountData[2]` = `"2FAXYZ"` (2FA code)
  * `$accountData[3]` = `"103.83.77.15:9898"` (Proxy)
* Step 2: Use the action Count passing in the array `$accountData` just split, and name the output variable as `$infoCount`.

After running, the variable `$infoCount` will receive the value of `4`. You can use this result in conjunction with If blocks to check (for example: If `$infoCount = 4` means the account has enough structural information, then proceed to run the login script, otherwise skip to avoid errors).

<figure><img src="/files/PEDcyc7Z2tBPIEgsJLrU" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/axWscllMURfHeeQP8RHU" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/BrSIQMI4lak1Y27clzmD" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/98sGoekOO48K92mIhSES" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/automate-en/action-guides/variables/count.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
