Pasquale Caira
Pasquale Caira

Reputation: 1

File watcher to check and sleep if file does not exist, Unix

import os.path
import os
import glob
import time

list_dir ='/path/to/file'
os.chdir(list_dir)
FILE_NAME = glob.glob('XXX_XXXX_o000000375*')
path_to_files = glob.glob( os.path.join(list_dir, 'XXX_XXXX_o000000375*'))


if ( not os.path.isfile(FILE_NAME)):
    print("error: %s file not found" % FILE_NAME)
else:
    print("Setting WAGs jail using %s ..." % FILE_NAME)

Im new to this and Im trying to create a script to look for a file and if one is not present then to sleep and try again. When I run it I get this error: Traceback (most recent call last):

File
    "createfile.py", line 20, in <module>
        if ( not os.path.isfile(FILE_NAME)):   File "/usr/lib64/python2.6/genericpath.py", line 29, in isfile
        st = os.stat(path) TypeError: coercing to Unicode: need string or buffer, list found

Can someone please help me with my issue?

Upvotes: 0

Views: 109

Answers (1)

farhawa
farhawa

Reputation: 10417

FILE_NAME is not a file, it's a list of path's and that's because you use glog.glob() as indicated here:

glob.glob(pathname)

Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. pathname can be either absolute (like /usr/src/Python-1.5/Makefile) or relative (like ../../Tools//.gif), and can contain shell-style wildcards. Broken symlinks are included in the results (as in the shell).

Upvotes: 1

Related Questions