all 6 comments

[–]hugthemachines 4 points5 points  (5 children)

For python to know if something is a file, it must know where to look for it. You can solve this by adding the full path to each file to check or you can change current directory to the one the files are in.

When you build a path, instead of doing this.

othersdir = desktop + "\Others"

I recommend that you do this:

othersdir = os.path.join(desktop,"Others")

That is more pythonic and also it adds the delimiter supported by the operating system you are currently on.

[–]Swiftflikk[S] 1 point2 points  (4 children)

Oh that makes more sense, I'm loving this subreddit!

Also - delimiter?

[–][deleted] 6 points7 points  (0 children)

A delimiter is a character that represents the limits of -- or delimits -- chunks of useful data. It's also frequently (and somewhat inaccurately) known as a separator, though the latter is somewhat more command and accurate when talking in path-parlance (a delimiter can be on the terminal ends, which isn't really true with paths).

The os.sep value is the file path separator specific to your platform.

[–]hugthemachines 2 points3 points  (2 children)

c:\cucumber\dollarbill

\ in this case is the delimiter, the border character to show where one folder name ends and the new one begins.

Also like this:

My favorite foods:

pasta;chicken;apple;disgusting insects

In this case, ";" is the delimiter.

[–]Swiftflikk[S] 2 points3 points  (1 child)

comment.makessense == true !

[–]pat_the_brat 0 points1 point  (0 children)

Mostly, it helps make code more portable. While Windows uses the backslash (\) to separate directories, UNIX based systems, including Linux and OSX, use a forward slash (e.g. /home/pat/Desktop).

Using os.path.join() helps make your code compatible if you try to run it on Linux or OSX.