arealhobo
arealhobo

Reputation: 467

glob.glob print returns unknown character block

When I run my function, it shows the tuple as being empty, even though it should find something in the directory.

The first function "check_files('\\SERVER1\C$\DIRECTORY\', '*.pdf', 'Test 0')" Returns TRUE, since there is a file in the directory.

For the following functions, it returns FALSE, even though there are files in the directory. Doing a print statement of "Output" it shows

CHARACTER

This makes me think it cant find the directory and throwing the whole thing off.

What gives??

import os
import glob

def check_files(mydir, myext, name):
     check = mydir + myext
     print(str(check))
     Output = glob.glob(check)
          if Output == []: #FALSE
               print (str(name) + 'All Operational.')
          else: #TRUE
               print (str(name) + 'I see some files here, please check the process.')



check_files('\\\SERVER1\\C$\\DIRECTORY\\', '*.pdf', 'Test 0')
check_files('\\\10.2.2.1\\Directory\\', '*.pdf', 'Test 1: ')
check_files('\\\10.3.2.1\\Directory\\', '*.pdf', 'Test 2: ')
check_files('\\\10.4.2.1\\Directory\\', '*.pdf', 'Test 3: ')

Upvotes: 0

Views: 35

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 60984

You need to escape all of the \ characters. Try running print('\1') to see why.

check_files('\\\\10.2.2.1\\Directory\\', '*.pdf', 'Test 1: ')

etc.

Upvotes: 1

Related Questions