How to delete a windows file with EXEC node

#1

How do I delete a file using the EXEC node? It works great with a Pi, but I’m sure Windows is preventing me from deleting.

If I go to cmd, on Windows, I type:
del c:\users\user\documents\filename.csv

I get Access is denied.

If I type del /p c:\users\user\documents\filename.csv
It will ask if I am sure that I want to delete the file.

I have even tried \q (quiet), but it gives me Access denied.

Any help would be great!

Thanks,
Mike

0 Likes

#2

on windows you may need to double escape \
so c:\\users\\ … etc

0 Likes

#3

Looks like this forum might require typing in triple \ to get double \\ into posts :slight_smile:

c:\\users\\ … etc

0 Likes

#4

Hah ! You are so right.

0 Likes

#5

In addition to Dave’s thought. How are you running Node-RED? If you are running it from the scheduler, is it running as a user or as System? That could make a difference.

0 Likes

#6

Or just use forward slash as that works as well.

0 Likes

#7

Sorry for just responding. Been out for a while. I am running NR as a service. I decided to handle it by avoiding Windows all together! I am sending a request via MQTT to my Raspberry Pi and handling the SQL, Emailing and file deletion from there. Everything works well!

[{"id":"69b307ae.5bbbc8","type":"comment","z":"8ed48002.ec4c3","name":"Raw HT Data Export","info":"","x":110,"y":260,"wires":[]},{"id":"ef25ec94.c3efd","type":"function","z":"8ed48002.ec4c3","name":"SQL Function","func":"stDt = msg.payload.startDate;\nedDt = msg.payload.endDate;\n\npld = \"SELECT Topic, CycleStart, Timestamp, id \";\npld = pld + \"FROM MQTTData \";\npld = pld + \"WHERE Timestamp BETWEEN \";\npld = pld + \"'\" + stDt + \"' and '\" + edDt + \"'\";\npld = pld;\n\nmsg.payload = pld;\nreturn msg;\n\n\n\n\n","outputs":1,"noerr":0,"x":380,"y":300,"wires":[["1babf44c.cf98ec"]]},{"id":"1babf44c.cf98ec","type":"MSSQL","z":"8ed48002.ec4c3","mssqlCN":"88d9a2f3.c5119","name":"MSSQL","query":"","outField":"payload","x":540,"y":300,"wires":[["106da5cf.b0330a"]]},{"id":"106da5cf.b0330a","type":"change","z":"8ed48002.ec4c3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\t  payload[0].$join($keys(), \",\"),\t  payload[].$join(*.$string(), \",\")\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":300,"wires":[["bd8597ae.87c528"]]},{"id":"bd8597ae.87c528","type":"split","z":"8ed48002.ec4c3","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":850,"y":300,"wires":[["57dbf5b2.60f2ec"]]},{"id":"57dbf5b2.60f2ec","type":"file","z":"8ed48002.ec4c3","name":"","filename":"/home/pi/RawMQTTData.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","x":1060,"y":300,"wires":[]},{"id":"6c1cdfe.d86322","type":"exec","z":"8ed48002.ec4c3","command":"rm /home/pi/RawEfficiencyData.csv","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1160,"y":240,"wires":[[],[],[]]},{"id":"36d02f7d.7854f","type":"function","z":"8ed48002.ec4c3","name":"","func":"msg.to = msg.payload.to;\nmsg.payload = '';\nmsg.topic = 'RawMQTTData Export'\nmsg.attachments = [{\n    filename: 'RawMQTTData.csv',\n    path: '/home/pi/RawMQTTData.csv'\n}];\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":340,"wires":[["27e45f60.de53e","53b488bd.557158"]]},{"id":"27e45f60.de53e","type":"e-mail","z":"8ed48002.ec4c3","server":"smtp.gmail.com","port":"465","secure":true,"name":"","dname":"","x":850,"y":340,"wires":[]},{"id":"53b488bd.557158","type":"delay","z":"8ed48002.ec4c3","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":860,"y":380,"wires":[["a26b02c8.4c3d2"]]},{"id":"a26b02c8.4c3d2","type":"exec","z":"8ed48002.ec4c3","command":"rm /home/pi/RawMQTTData.csv","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1150,"y":380,"wires":[[],[],[]]},{"id":"47783d56.3e95b4","type":"delay","z":"8ed48002.ec4c3","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":340,"wires":[["36d02f7d.7854f"]]},{"id":"546e3c1b.9e4cf4","type":"delay","z":"8ed48002.ec4c3","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":860,"y":240,"wires":[["6c1cdfe.d86322"]]},{"id":"c72d5563.b5b1e8","type":"json","z":"8ed48002.ec4c3","name":"","property":"payload","action":"","pretty":false,"x":230,"y":300,"wires":[["ef25ec94.c3efd","47783d56.3e95b4"]]},{"id":"35aa6c38.388844","type":"mqtt in","z":"8ed48002.ec4c3","name":"","topic":"HTData","qos":"2","broker":"302d9396.8bf4ec","x":90,"y":300,"wires":[["c72d5563.b5b1e8"]]},{"id":"88d9a2f3.c5119","type":"MSSQL-CN","z":"","name":"Dev","server":"10.0.0.120","encyption":true,"database":"Dev"},{"id":"302d9396.8bf4ec","type":"mqtt-broker","z":"","name":"","broker":"10.0.0.2","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]
0 Likes