0

I trying to analize some file that come through a ftp transfer from many clients to my server (pc). So, I'm constantly getting a list o files using

for dirpath, _, filenames in walk(directoryPath):
    for filename in [f for f in filenames if f.endswith(".jpg")]:
        files.append(path.join(dirpath, filename))
return files

Because this is running much faster than the file transfer, the script try to open the image, throwing an exception, and I omit it until no more exceptions get throwed. But even there the analysis fail.

I know that my analysis code works because this only occur with new files, and no with the ones that was there on first run.

I use

os.access()

To get the file status, but this only give me the permissions, and no if some process are currently writing data on it.

Jose Truyol
  • 185
  • 13

1 Answers1

0

I actually found a solution. I'm using proftpd in Ubuntu, and it have a configuration when can add a sufix and/or prefix to the filename when is still on transfer, and then rename it to the original name.

I just had to ignore all file with the prefix or sufix. With this I guarantee that I open the file when is complete.

Jose Truyol
  • 185
  • 13