How to delete files using the syntax '*' with python3?
<p>There are some files that named like percentxxxx.csv,percentyyyy.csv in the dir.I want to delete the files with the name begins with percent.</p>

<p>I find the <code>os.remove</code> function maybe can help me,bu I don't konw how to solve the problem.</p>

<p>Are there any other functions can delete files using the syntax percent*.csv ?</p>

<p>The following is my method:</p>

<pre><code>system_dir=os.getcwd()
for fname in os.listdir(system_dir):
    # print(fname)
    if fname.startswith('report'):
        os.remove(os.path.join(system_dir, fname))
</code></pre>

<p><strong>I mainly want to know whether there are more easier methed ,for example using * syntax in the method.</strong>       </p>

<p>Use <a href="https://docs.python.org/3.1/library/glob.html#module-glob" rel="nofollow">glob</a>:</p>

<pre><code>import os
import glob
for csv in glob.glob("percent*.csv"):
  os.remove(csv)
</code></pre>

python python-3.x delete-file