A file can have multiple extensions but name of the file will remains same. I have tried
import os.path
os.path.isfile("Filename")
but this code is looking at the extension of the file also.
This would list all files with same name but different extensions.
import glob
print glob.glob("E:\\Logs\\Filename.*")
You could use this check instead.
import glob
if glob.glob("E:\\Logs\\Filename.*"):
print "Found"
Refer this post.
Try this.
import os
def check_file(dir, prefix):
for s in os.listdir(dir):
if os.path.splitext(s)[0] == prefix and os.path.isfile(os.path.join(dir, s)):
return True
return False
You can call this function like, e.g., check_file("/path/to/dir", "my_file")
to search for files of the form /path/to/dir/my_file.*
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With