I made it!!!
I’ll write the solution here in case someone face the same issue. In my case, where I am working on an addon, I had to type dir
like this dir = os.path.join(os.path.dirname(__file__), "icons")
. But if someone is working on a simple script, has to type dir
like this dir = os.path.dirname(bpy.data.filepath)
.