There's something fundamentally strange with what you're doing. To associate a file with a directory index is a risky thing to do, since file ordering in directories isn't portable across types of file systems. In general, you can't assume a directory "position" for a file unless the directory is static. Even then, that's risky.
What is it that you're doing that requires a directory "index"?