0

Im writing a program in python for sorting my huge folder with a lot of junk, but also some good pictures that I would like to keep and sort by some parameters into an album.

Im not very good at programming, but I should be able to get this one right (but looks like im wrong lol).

This is the case: When selecting the pictures, and sorting them in a new dedicated folder. The program reports every picture was moved. And there is no pictures left in the source folder, but 1 or 2 pictures are missing when i check folder created with all the moved pictures.

I'v tried to check that the file is removed from source and is created in destination like this

I use shutil and a counter to move, and count every moved file like:

shutil.move(src, dest) 
    movedFiles += 1

if not created in new destination:

    if not path.isfile(newFile):
                    print(...)
                    

and

if not removed from old destination:

  if path.isfile(oldFile):
              print(...)
                   

I dont know if this is sufficient information to see any problems or errors i should check, please let me know. Im new here, so im kind of a noob :|

What is the best way to start error searching something like this? Its about 5k files and there might be some copies with the same name, but stored in different folders, so i can't just search by names either. Maybe i could try to hash the images and search for which hash is missing?

sainupangad
  • 115
  • 9
  • `The program reports every picture was moved` What is reporting that it has moved and how does it know? Often times people assume they know too much and it's that little misconception that keeps them up at night solving the issue. It's obvious that the source directory is successfully being emptied, but are you deleting files you don't know about? You should minimize your possibility for error. Grab a couple files and create a little test_directory with them and run the program on that. Plus why would you want to run a might work program on all of your files anyway? you could lose files. – Thomas May 27 '21 at 19:57
  • 1
    I could be wrong, but I believe `shutil.move()` will overwrite files with the same name. [See this thread.](https://stackoverflow.com/questions/31813504/move-and-replace-if-same-file-name-already-exists). – will-hedges May 27 '21 at 19:59
  • Thomas: Thats true. what i mean by reporting is not much more than i run shutil. move() without an error. I'v tested it on some folders and everything worked. Tried to cover all edgecases. Im only working on copies of the original folder, if not i would be f*** by now – Einar Johansen May 27 '21 at 20:12
  • Chemicalwill: Before i perform a call to move a file, i first find the destination path based on the date etc. Then i check if there already is a file with that name in that location. If the files dont have equal size, ill give it a New name before moving. – Einar Johansen May 27 '21 at 20:16

0 Answers0