0

My code is :

import time
import os
import os.path

dir = raw_input('Temp files folder directory: ')
deletedFiles = 0

check = True

def checkTempFiles(tempDir):
    time.sleep(5) #900 for 15 mins
    files_in_dir = os.listdir(dir)
    for file_in_dir in files_in_dir:
        ext = os.path.splitext(file_in_dir)[1].lower()
        if ext != '.php' :


ctime = time.ctime(os.path.getctime(file_in_dir))
            if ctime > ctime + 900:
                os.remove(ctime > ctime + 900)
                deletedfiles += 0



while check == True:
    checkTempFiles(dir)

And apparently I get an error on the line:

ctime = time.ctime(os.path.getctime(file_in_dir))

Please help me and thanks in advance. I am trying to get the creation time of the file and check stuff as you see up^. But it doesnt work due to that error and I cant solve it

ntakouris
  • 898
  • 1
  • 9
  • 22
  • The variable you are using, `file_in_dir`, is defined inside the function `checkTempFiles`, so you cannot access it outside the scope of the function. Or maybe your example has an indentation problem, and you should indent the `ctime = ...` line to match the `if` statement. – Thales MG Sep 10 '13 at 19:48
  • `ctime` != "file creation time". In fact, most Linux file systems do not keep track of file creation time at all... – twalberg Sep 10 '13 at 20:33
  • See here: http://stackoverflow.com/questions/1408272/get-file-creation-time-with-python-on-linux You probably can't. – Fred Mitchell Sep 10 '13 at 21:05
  • 'file_in_dir name' is No such file or directory – ntakouris Sep 11 '13 at 09:34
  • Indentation is not an error(It was paster weirdly somehow) . Neither are the spaces. The function ends with the deletedFiles += 1 – ntakouris Sep 11 '13 at 09:48
  • @user2728815 ... except that there is no `deletedFiles += 1`, unless you really mean the `deletedFiles += 0` NO-OP there... – twalberg Sep 11 '13 at 13:38

0 Answers0