How to check if a file is exist in data folder by code?

Yes! Just pass an empty string "" to dataPath():

dataFolderPath = this.dataPath('') + '/'
print dataFolderPath

… or to dataFile():

dir = this.dataFile('')
dataFolderPath = dir.path + '/'
print dataFolderPath

However, if you need all files within the sketch’s “data/” folder, like all images for example, you can use listPaths(), passing the “data/” folder path + a string w/ all desired “extensions=,”: :sunglasses:

PICS_EXTS = 'extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp'

dir = this.dataFile('')
imagePaths, imagesFound = (), 0

if dir.isDirectory():
    imagePaths = this.listPaths(dir.path, PICS_EXTS)
    imagesFound = len(imagePaths)

printArray(imagePaths)
print 'Found %d image(s)' % imagesFound
2 Likes