Python doesn't see the directories I create
Diez B. Roggisch
deets at nospam.web.de
Thu Aug 30 04:54:09 EDT 2007
mr_gadget schrieb:
> When I create a subfolder, python is not seeing it. Can someone please
> explain this behaviour ? I just started with python, read the tutorial over
> the weekend and am writing my very first script. So I may not be seeing
> something. Both os.path and glob.glob seem not to see a folder I created.
> Other sibling folders seem to work fine. On a whim I tried paths with \\
> double slashes and that worked. But why should single slashes work for some
> folders and not for others ??
>
> What I need is to match a bunch of files in a folder with
> glob.glob(C:\enhancement\rawfiles\*.bin.gz) and send them to a function that
> unzips them. But I always get []. Yes the folder does have my files, and I
> checked all permissions etc, everything looks identical to the other folders
> which python IS seeing. Same problem on my vista pc too.
>
> Behaviour reproduced below.
>
> C:\Enhancement>dir /ad
>
> Volume in drive C has no label.
>
> Volume Serial Number is 8056-41E7
>
> Directory of C:\Enhancement
>
> 08/28/2007 06:15 PM <DIR> .
>
> 08/28/2007 06:15 PM <DIR> ..
>
> 08/28/2007 06:07 PM <DIR> BSA Documentation
>
> 08/28/2007 05:56 PM <DIR> output
>
> 08/29/2007 07:08 PM <DIR> rawfiles
>
> 08/23/2007 04:38 PM <DIR> SnapCell2.3.2
>
> 08/28/2007 06:15 PM <DIR> test
>
> 0 File(s) 0 bytes
>
> 7 Dir(s) 35,703,283,712 bytes free
>
> C:\>python -V
>
> Python 2.5.1
>
> C:\>python -c "import os; print os.path.exists('C:\enhancement\output')"
>
> True
>
> C:\>python -c "import os; print os.path.exists('C:\enhancement\rawfiles')"
>
> False
>
> C:\>python -c "import os; print os.path.exists('C:\\enhancement\\rawfiles')"
>
> True
>
> C:\>python -c "import glob; print glob.glob('C:\enhancement\rawfiles\*')"
>
> []
>
> C:\>python -c "import os; print os.path.exists('C:\enhancement\test')"
>
> False
>
> C:\>python -c "import os; print
> os.path.exists('C:\enhancement\snapcell2.3.2')"
I'm pretty sure it's a missing backslash escape thingy. Either use \\
for a backslash in paths, or just the forward slash, it works as well.
And case-sensitivity might be an issue as well.
Diez
More information about the Python-list
mailing list