Deleting all files from a folder, without deleting sub-directories?

1,121 views
Skip to first unread message

M Hanes

unread,
Feb 18, 2016, 7:30:39 PM2/18/16
to robotframework-users
Hi all,
I have a test scenario where I create a .txt file in a network folder directory, but before creating this file I need to make sure there are no other .txt files in the directory (there may be other test files from people who are running manual tests and then they left their test file in the directory when they were finished.) So I need a step that will check for any .txt file that may have been left behind, and then delete the file... or just delete any file(s) that it finds in the directory. I would use the "Empty Directory" keyword, but that deletes all sub-directories as well, and I do have a couple of sub-directories within the folder that I can't delete or it will cause big problems.

Does anyone have suggestions on how I could do this?

Thanks!

Kevin O.

unread,
Feb 23, 2016, 11:19:25 AM2/23/16
to robotframework-users
Try this:
@{txt files}=    List Directory    ${path}    *.txt    absolute=${True}
Remove Files    @{txt files}

Pekka Klärck

unread,
Feb 23, 2016, 11:34:52 AM2/23/16
to Kevin Ormbrek, robotframework-users

Remove Files supports patterns too:

    Remove Files    ${path}/*.txt

Sent from my mobile.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

M Hanes

unread,
Feb 23, 2016, 4:56:09 PM2/23/16
to robotframework-users, korm...@gmail.com
Oh nice! Thank you guys!


On Tuesday, February 23, 2016 at 8:34:52 AM UTC-8, Pekka Klärck wrote:

Remove Files supports patterns too:

    Remove Files    ${path}/*.txt

Sent from my mobile.

23.2.2016 6.19 ip. "Kevin O." <korm...@gmail.com> kirjoitti:
Try this:
@{txt files}=    List Directory    ${path}    *.txt    absolute=${True}
Remove Files    @{txt files}

On Thursday, February 18, 2016 at 6:30:39 PM UTC-6, M Hanes wrote:
Hi all,
I have a test scenario where I create a .txt file in a network folder directory, but before creating this file I need to make sure there are no other .txt files in the directory (there may be other test files from people who are running manual tests and then they left their test file in the directory when they were finished.) So I need a step that will check for any .txt file that may have been left behind, and then delete the file... or just delete any file(s) that it finds in the directory. I would use the "Empty Directory" keyword, but that deletes all sub-directories as well, and I do have a couple of sub-directories within the folder that I can't delete or it will cause big problems.

Does anyone have suggestions on how I could do this?

Thanks!

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages