HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonMinor

File deletion takes a long time to delete files

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
filedeletelongtimefilesdeletiontakes

Problem

I have a script I need to "duplicate" and modify to allow it to delete certain images based on properties I give this app/script. Currently the script just moves/sorts the images into folders based on numbers (e.g. each folder has 5000 images before a new folder is created and more images propagated).

The requirement of this is:

  • I need to remove any images that are; width



  • I need to increase the speed of which they are filtered (currently 5/second)



  • I need to have interchangeable code so that I can apply/remove this to/from the sorting script and be able to add conditions (e.g. is the file corrupt?)



Issue:

The deletion method works, but only just. Where the moving of files into folders can do 60,000 images in around 30 seconds I can't delete and move at the same or similar rate. Instead I can do about 5 images per second.

Sorting Script:

```
def confirmIt():
#======== Confirm Selection and Move files to new sub-directory:
# Confirm selection and move files to new sub-directory

source = folderPath.get() # set source path
if source: # make sure not blank
fileCount = 0 ## Counts the number of files going into a folder
folderCount = 1 ## Helps count the folders
dest = os.path.join(source, "Folder ("+str(folderCount)+")") ## Set the folder destination for manual filtering

for fname in os.listdir(source):
if fname.lower().endswith(extensions): ## Ensure we are looking at images
image_path = os.path.join(source, fname) ## set the source location of the image
fileCount = fileCount+1 ## Start counting how many files we have in this folder

if (fileCount

Solution

I have managed to create a workaround while doing this:

  • I have changed the GUI code to run in the Python CMD to let the user know files are being moved/deleted.



  • I have used the code found in this post. This basically fixes errors as well as some time problems between python and Tkinker. I will take a further look into this when the need arises.



Answer:

  • Edited code with fix from Stack Overflow linked above.



  • Changed user feed back to Python-based command line instead of Tkinker GUI.

Context

StackExchange Code Review Q#100777, answer score: 2

Revisions (0)

No revisions yet.