# How to delete text file

**URL:** <https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730>\
**Category:** General Discussion\
**Created:** [June 29, 2012, 5:53am UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730 "2012-06-29T05:53:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mubin](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mubin](https://forum.inductiveautomation.com/u/mubin)\
**Post date:** [June 29, 2012, 5:53am UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/1 "2012-06-29T05:53:10Z")

</div>

how to delete a text file programmatically in ignition by using event client scripts?  
and what is script for this?  
please anyone give me the solution for this.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 29, 2012, 10:43am UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/2 "2012-06-29T10:43:33Z")

</div>

short example:

`import os
os.remove("c:\\temp\\readme.txt")`

---

<div class="post-metadata">

**Author:** ![mubin](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mubin](https://forum.inductiveautomation.com/u/mubin)\
**Post date:** [June 30, 2012, 5:55am UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/3 "2012-06-30T05:55:29Z")

</div>

is this for linux environment?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 30, 2012, 9:09am UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/4 "2012-06-30T09:09:02Z")

</div>

the specific example script was for a Windows file. Just put whatever path to the file inside the quotes and you should be good to go. 🙂

---

<div class="post-metadata">

**Author:** ![mubin](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mubin](https://forum.inductiveautomation.com/u/mubin)\
**Post date:** [July 28, 2012, 11:33am UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/5 "2012-07-28T11:33:38Z")

</div>

thank you it is worked under linux also

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [October 4, 2021, 7:15pm UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/6 "2021-10-04T19:15:04Z")

</div>

Could this also be applied to a file type? Lets say I want to delete any csv file in a folder. Could I use \*.csv instead of a specific file? I will not know what the name of the file is, just that its a csv file.

---

<div class="post-metadata">

**Author:** ![dillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dillon/32/81537_2.png) [@dillon](https://forum.inductiveautomation.com/u/dillon)\
**Post date:** [October 4, 2021, 7:25pm UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/7 "2021-10-04T19:25:04Z")

</div>

Yes this is for any type of file.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [October 4, 2021, 7:34pm UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/8 "2021-10-04T19:34:11Z")

</div>

Tried this and get an error back:

```auto
	import os

	filepath = 'C:\\Recipes\\BT548647\\*.csv'
	os.remove(filepath)

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/6/e602791babd47b7955ae712fb5e9cd7809be4455.png)

---

<div class="post-metadata">

**Author:** ![dillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dillon/32/81537_2.png) [@dillon](https://forum.inductiveautomation.com/u/dillon)\
**Post date:** [October 4, 2021, 7:47pm UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/9 "2021-10-04T19:47:43Z")

</div>

> [@michael.black](#):
>
> ```auto
> import os
> 
> filepath = 'C:\Recipes\BT548647\*.csv'
> os.remove(filepath)
> 
> ```

Try with the edited code. I think the double slashes are giving you issues...

---

<div class="post-metadata">

**Author:** ![Paul.Scott](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.scott/32/4578_2.png) [@Paul.Scott](https://forum.inductiveautomation.com/u/Paul.Scott)\
**Post date:** [October 4, 2021, 7:51pm UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/10 "2021-10-04T19:51:36Z")

</div>

FWIW, not certain if `os.remove` accepts wildcards natively. [Seems like you could make use of `glob` though.](https://stackoverflow.com/a/5756937)

```auto
import os
import glob

files = glob.glob("C:\\Recipes\\BT548647\\*.csv")
for f in files:
	os.remove(f)

```

[https://docs.python.org/2.7/library/glob.html](https://docs.python.org/2.7/library/glob.html)

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [October 4, 2021, 8:00pm UTC](https://forum.inductiveautomation.com/t/how-to-delete-text-file/4730/11 "2021-10-04T20:00:05Z")

</div>

This did work. Thanks. For the function script I am already using the glob library so that works too. I also got the following to work:

```auto
import os
	from os import listdir
	my_path = 'C:\\Recipes\\BT548647\\'
	
	for file_name in listdir(my_path):
		if file_name.endswith('.csv'):
			os.remove(my_path + file_name)

```

Think I will use your route though. cleaner and easier.

still not sure why my initial script did not work. it seems as if it would. maybe because the path and filename have to be separate?
