Course 2 week 1 GRADED FUNCTION: split_data

I’m getting an error . Seems like I must be doing something conceptually wrong. I’m creating a list containing the contents of our source directory using os.listdir. Then using a for loop to test the length of each element of that list for file size greater than 0 using os.path.getsize. Seems like the things in the list may not be what I think they are? Can you point me in the right direction? Thanks and have a great day! George

FileNotFoundError Traceback (most recent call last)
in <cell line: 37>()
35 # Run the function
36 # NOTE: Messages about zero length images should be printed out
—> 37 split_data(CAT_SOURCE_DIR, TRAINING_CATS_DIR, VALIDATION_CATS_DIR, split_size)
38 split_data(DOG_SOURCE_DIR, TRAINING_DOGS_DIR, VALIDATION_DOGS_DIR, split_size)
39

1 frames
/usr/lib/python3.10/genericpath.py in getsize(filename)
48 def getsize(filename):
49 “”“Return the size of a file, reported by os.stat().”“”
—> 50 return os.stat(filename).st_size
51
52

FileNotFoundError: [Errno 2] No such file or directory: ‘5935.jpg’

I figured it out. No need to reply.

HI I have a different problem now with this assignment. I tried to break the list of files into test and train by multiplying the length of the list of files with non zero size by the SPLIT_SIZE and then taking the floor using math.floor() to get the index I need to split the list of files. Only problem is math has not been imported so I assume I am supposed to use some other method for splitting the data. I see no hint of how to do this. None of the functions imported seem to be made for splitting data into two parts. Can you point me in the right direction? Here is my error message. filename is zero length, so ignoring.

NameError Traceback (most recent call last)
in <cell line: 37>()
35 # Run the function
36 # NOTE: Messages about zero length images should be printed out
—> 37 split_data(CAT_SOURCE_DIR, TRAINING_CATS_DIR, VALIDATION_CATS_DIR, split_size)
38 split_data(DOG_SOURCE_DIR, TRAINING_DOGS_DIR, VALIDATION_DOGS_DIR, split_size)
39

in split_data(SOURCE_DIR, TRAINING_DIR, VALIDATION_DIR, SPLIT_SIZE)
31 else: print(“filename is zero length, so ignoring.”)
32
—> 33 index = math.floor(len(FilesGt0)*SPLIT_SIZE)
34 random.sample( FilesGt0, len( FilesGt0))
35 copyfile(FilesGt0[:index], TRAINING_DIR)

NameError: name ‘math’ is not defined

OK Solved it no need to reply