hey guys and girls i am having a bit of a problem with my code
import os,string,sys,pprint,time,glob from datetime import datetime, timedelta fileList = os.walk('.')#if i use glob.glob it does not show any files now = datetime.now() TWA = now + timedelta(days=-1) #print(TWA) files=str() for files in fileList: fileStats = os.stat(files)#BUT using os.walk causes this function to fail daysOld = (int(now - fileStats.st_mtime)) if daysOld < TWA: os.remove(files) print('Deleting: '+ files)
i can use glob.glob and run the code with no errors but it will not print the files
so i tried using os.walk as its quicker and more effective.
the only thing is that now my code to find the files date has stopped working and receive this error
Traceback (most recent call last): File "C:\Documents and Settings\Administrator\My Documents\test dir\dir1\deletetv.py", line 11, in <module> fileStats = os.stat(files) TypeError: Can't convert 'tuple' object to str implicitly
if any one could help me or point me in the right direction to why it would fail.
i have a basic knowledge of python and love learning new features but i cant seem to find anything which would stop os.stat working!
thanks for looking people.