1

I have several *.dbf files in a folder. Their names are of 8 digits such as 00043232.dbf, 00458283.dbf, 32349999.dbf, 83721092.dbf, 12139999.dbf, 48729999.dbf, ...

I want to delete files that end with 9999. So, in this case, I want to erase 32349999.dbf, 12139999.dbf, 48729999.dbf.

I can I do that in Python?

2 Answers 2

3

A simple way would be to us glob.glob to find the relevant files, and then use os.unlink() on it:

import glob
import os

for file_path in glob.glob('*9999.dbf'):
    os.unlink(file_path)
Sign up to request clarification or add additional context in comments.

Comments

1

glob, os.unlink()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.