>> >> >> >> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >> >> >> > 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 <swift...@swiftone.org> wrote: > >> On Tue, May 10, 2011 at 8:17 AM, Tommy Bell <to...@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 >> swift...@swiftone.org >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > > > -- > Jorge Romero > -------------- next part --------------
Actually, I have had no problems using forward slashes (ie, "C:/User/Data/etc" being a valid path) at all. There's also os.path.normpath() if you feel that there's a need to convert forward slashes to backward slashes, or the raw string literal, r (r"C:\User\Data\etc"). Sorry for not snipping much of the message, smartphone is a bit clunky for that, to say theleast. Best regards, Robert S _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor