i have problem with glob.glob() in remotely directory

Steve Holden steve at holdenweb.com
Thu Feb 26 07:56:19 EST 2009


Chris Rebert wrote:
> On Thu, Feb 26, 2009 at 1:05 AM, lameck kassana <chelaskk at gmail.com> wrote:
>> hey i want to count number of files in remote computer
>>
>> example of my code is
>>
>> import glob
>> import os
>> import time
>> from datetime import date
>> today=date.today()
>> dir_count, file_count=0, 0
>>
>> for files in glob.glob('\\192.168.0.45\files\*.txt'):
> 
> Remember that *backslash is the escape character* in Python, so you
> need to double-up your backslashes in the string literal (or just use
> forward slashes instead, Windows doesn't seem to care for Python in
> most cases). Right now, the path really only starts with 1 backslash
> and it has a formfeed character in it (\f), so it's obviously invalid;
> thus, your problem.
> 
> So you want:
> #looks ugly, doesn't it?
> for files in glob.glob('\\\\192.168.0.45\\files\\*.txt'):
> 
> Or:
> #will probably but not assuredly work
> for files in glob.glob('//192.168.0.45/files/*.txt'):
> 
Or:

for files in glob.glob(r'\\192.168.0.45\files\*.txt'):

Raw string literals are very useful for handling strings with lots of
backslashes in them.

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list