There are two problems with this:
datetime.time(create_time)
First, you're constructing a time object, which represents a:
time of day, independent of any particular day
In other words, it represents something like "10:30:00.000", not "2018-Aug-29 10:30:00.000". So, that isn't much use if you want to find files that are "newer than yesterday". What you want is a datetime object.
Second, you can't just throw some random value at the constructor and hope it's the right thing.
The getctime function is:
a number giving the number of seconds since the epoch
The time constructor takes:
time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
And the datetime constructor takes:
datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
So, you have a number of seconds, and you're trying to use that as an hour or a year.
The function you want to use is fromtimestamp:
Return the local date and time corresponding to the POSIX timestamp
So, what you want is:
datetime.datetime.from_timestamp(create_time)
Also, be aware that what getctime returns is:
the system’s ctime which, on some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time
So, using that for something named create_time is at best non-portable and Windows-specific, and at worst (if you're not actually on Windows) wrong.
Also:
from_date = datetime.datetime.now() - datetime.timedelta(days=-1)
You're subtracting -1 days, which is the same as adding 1 day.
So, instead of looking for files less than 24 hours old, you're looking for files more than 24 hours in the future. Either use +, or use days=1.
While we're at it:
if datetime.time(create_time) >= from_date and datetime.time(create_time) <= to_date:
Instead of creating the timestamp object twice and doing two separate comparisons, why not just use a chained comparison?
if from_date <= datetime.datetime.from_timestamp(create_time) <= to_date:
Or, maybe better, move the construction out of the test:
create_time = datetime.datetime.from_timestamp(os.path.getctime(file))
if from_date <= create_time <= to_date:
datetime.datetime, notdatetime.time. And you want to use thefromtimestampclass method to create them fromtime_t-style seconds-since-1970 timestamps (unless you're on an old version of Python that didn't have that method yet).getctimemean "created time"; everywhere else it returns the time of the last metadata update.getmtimeis more portable and usually the correct thing to test (since the time of last modification is the time the exact data in the current file first existed). Otherwise, you clearly need to usedatetime.datetimes, notdatetime.times, because adatetime.timecan't represent a concept of "more than 24 hours ago" in the first place.to_date = datetime.datetime.now()and theglob.globcall), nothing should be created after now, and in the rare cases it occurs (immediately after a clock sync that moves the clock backwards or the like), you probably still want to treat them as "created in the last 24 hours".