Forums

Python Script Fails on Scheduler

Hi, Ive got a python script that runs fine when I go to the file and hit run. However the script fails when the scheduler runs it. What could be causing this?

This is my script:

import time
import os
import shutil
import stat

for i in os.listdir():
    if os.path.isdir(i):
         shutil.rmtree(i)

This is the error I get when it is ran by scheduler

Traceback (most recent call last):
  File "filepath/myscript.py", line 7, in <module>
    for i in os.listidir():
TypeError: listdir() takes exactly 1 argument (0 given)

2017-01-25 17:10:12 -- Completed task, took 0.00 seconds, return code was 1.

Im confused why this works when I manually run it but not when the schedule runs it.

when you run phyton scrips by the scheduler, the directory where it runs is the home directory, not the directory where your file is located you can check this with getcwd()

Thanks, That fixed it