File exists in a directory

Hello!

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

I hope someone can help me.

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

[{"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

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

[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

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