[Tutor] folder and file list

Jorge Romero jorgeromero178 at gmail.com
Wed May 11 00:08:27 CEST 2011


Is there any special reason for deploying that functionality from scratch by
yourself? Can't you use os bulit-in module?

Perhaps you can find this useful
http://docs.python.org/library/os.html#os.listdir. That way you don't deal
with OS peculiarities such as the one Brett Ritter pointed.

On Tue, May 10, 2011 at 8:45 AM, Brett Ritter <swiftone at swiftone.org> wrote:

> On Tue, May 10, 2011 at 8:17 AM, Tommy Bell <tommy at enkelthed.dk> wrote:
> > scandir('c:\tmp')
>
> > this doesnt work, I know why - but i dont know how to fix it.
> > The reason it doesnt work is because isfile requires a file, but current
> contains a path.
>
> Not quite.  Stick a "print path" as the first line in scandir.
>
> Notice that it doesn't print out c:\tmp
>
> The issue is that Windows (Well, DOS, back in the day) decided to use
> backslashes as the path separator, where the rest of the world
> (mostly) used slashes.  This meant that most programming languages use
> backslashes to "escape" characters to have special meaning.  Putting
> "\n" in a string puts in not an "n" but a newline character.  \t is a
> tab.  This causes you  (and many other windows programmers) a little
> bit of distress today, in many programming languages.
>
> To have your string recognize that your backslash is an actual real
> backslash you can escape it:
>  scandir('c:\\tmp')
>
> After that your code should work fine (it runs on my system, but I'm
> not on windows).
>
> This filepath issue has many details you can look up or ask about, but
> this should get you started.
>
> --
> Brett Ritter / SwiftOne
> swiftone at swiftone.org
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Jorge Romero
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110510/65da1319/attachment-0001.html>


More information about the Tutor mailing list