HOW TO: file with extension exists

Asked by JamesPanteleone

Hey,

I'm need to find if a file with extension .clm exists in a certian folder with only using Jython.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

--- a how to --- quick and dirty

import os
dir = "absolute-path-to-your-folder"
files = os.listdir(dir)
for f in files:
    full = os.path.join(dir, f)
    if not os.path.isfile(full): continue
    if not f.endswith(".clm"): continue
    break
print f # this is your file

more information:
http://www.jython.org/docs/library/os.html#files-and-directories
http://www.jython.org/docs/library/os.path.html

Revision history for this message
RaiMan (raimund-hocke) said :
#2

f contains the filename only and full contains the complete absolute path.

Revision history for this message
JamesPanteleone (jamesp) said :
#3

Thanks RaiMan, that solved my question.