擅长:python、mysql、java
<p>您可以使每个变量成为一个列表,并存储其中文件的名称:</p>
<pre class="lang-py prettyprint-override"><code>from os import listdir
from os.path import isfile, join
folder_path = '/home/youruser/example' # path to folder
# classify files
exfiles = []
normalfiles= []
for f in listdir(folder_path):
if isfile(join(folder_path, f)):
if f.startswith('EX'):
exfiles.append(join(folder_path, f))
else:
normalfiles.append(join(folder_path, f))
for fname in exfiles:
with open(fname) as f:
# do operations
</code></pre>