# File exists in a directory

**URL:** <https://discourse.nodered.org/t/file-exists-in-a-directory/82393>\
**Category:** General\
**Created:** [27 October 2023 10:06 UTC](https://discourse.nodered.org/t/file-exists-in-a-directory/82393 "2023-10-27T10:06:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![madmax](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@madmax](https://discourse.nodered.org/u/madmax)\
**Post date:** [27 October 2023 10:06 UTC](https://discourse.nodered.org/t/file-exists-in-a-directory/82393/1 "2023-10-27T10:06:31Z")

</div>

Hello!

Is there a way to check whether a file exists in a directory?

I hope someone can help me.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 October 2023 10:25 UTC](https://discourse.nodered.org/t/file-exists-in-a-directory/82393/2 "2023-10-27T10:25:37Z")

</div>

Do you mean check if a specific file exists in a directory, or check that the directory is not empty?

You can check for a specific file with a Read file node and a Catch node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/6/d6be5aea1b7702be0d4a8fb82f2fb1ad26be63e5.png)

```auto
[{"id":"727b1f926dc4948b","type":"group","z":"e3e44c2c66857cbf","style":{"stroke":"#0722fc","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#0722fc"},"nodes":["e855257cb1749702","68d8dfec0ae57d1f","b8811e0d2907a495","2adbe8694c1efbc2","6e0095b1808c2ce2","61385f488fd6f6c5"],"x":14,"y":359,"w":752,"h":122},{"id":"e855257cb1749702","type":"debug","z":"e3e44c2c66857cbf","g":"727b1f926dc4948b","name":"debug 428","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":400,"wires":[]},{"id":"68d8dfec0ae57d1f","type":"file in","z":"e3e44c2c66857cbf","g":"727b1f926dc4948b","name":"Read File","filename":"topic","filenameType":"msg","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":280,"y":400,"wires":[["61385f488fd6f6c5"]]},{"id":"b8811e0d2907a495","type":"inject","z":"e3e44c2c66857cbf","g":"727b1f926dc4948b","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"/home/pi/foo","x":130,"y":400,"wires":[["68d8dfec0ae57d1f"]]},{"id":"2adbe8694c1efbc2","type":"catch","z":"e3e44c2c66857cbf","g":"727b1f926dc4948b","name":"","scope":["68d8dfec0ae57d1f"],"uncaught":false,"x":250,"y":440,"wires":[["6e0095b1808c2ce2"]]},{"id":"6e0095b1808c2ce2","type":"change","z":"e3e44c2c66857cbf","g":"727b1f926dc4948b","name":"Does not exist","rules":[{"t":"set","p":"payload","pt":"msg","to":"Does not exist","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":440,"wires":[["e855257cb1749702"]]},{"id":"61385f488fd6f6c5","type":"change","z":"e3e44c2c66857cbf","g":"727b1f926dc4948b","name":"Exists","rules":[{"t":"set","p":"payload","pt":"msg","to":"Exists","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":400,"wires":[["e855257cb1749702"]]}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0fd68f50d4fa7521e97b6164b1ebf14a7ff8b46c.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 October 2023 10:47 UTC](https://discourse.nodered.org/t/file-exists-in-a-directory/82393/3 "2023-10-27T10:47:16Z")

</div>

Or you could use the stats node from node-red-contrib-fs-ops to test it.

---

<div class="post-metadata">

**Author:** ![madmax](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@madmax](https://discourse.nodered.org/u/madmax)\
**Post date:** [27 October 2023 10:55 UTC](https://discourse.nodered.org/t/file-exists-in-a-directory/82393/4 "2023-10-27T10:55:05Z")

</div>

[quote="jbudd, post:2, topic:82393"]  
Do you mean check if a specific file exists in a directory, or check that the directory is not empty?

You can check for a specific file with a Read file node and a Catch node  
[/quote] Thanks for the reply.

I would like to know whether a certain file exists

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 December 2023 10:55 UTC](https://discourse.nodered.org/t/file-exists-in-a-directory/82393/5 "2023-12-26T10:55:44Z")

</div>

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