Files in unix and windows

  • Thread starter Travis James Kleeburg
  • Start date
T

Travis James Kleeburg

I am trying to copy files from one directory into another using
shutil.copy. I am having a problem getting a usable path using
os.path.abspath because it doesnt return a string with the extra
backslashes and i was wondering if there was a better system call to use?
I am also looking for a system call so there wont be a problem between windows and
unix.
 
J

Jeff Epler

Which extra (back)slashes do you mean? Do you mean that os.path.abspath
strips the trailing separator characters from its argument?
'.'

This behavior doesn't seem to be specifically documented.

If preserving the trailing '/' when present is important, you can easily
get this behavior using os.path.abspath:
def myabspath(p):
hadsep = p and p[-1] in (os.sep, os.altsep)
p = os.path.abspath(p)
if hadsep: p = p + os.sep
return p
'/etc'

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBJ0ibJd01MZaTXX0RAg4mAJ9SUjjg8rDt4OY1YvVaNw8lSx9vAQCbBbk1
E6QV8mAC602+zN7/r8j3+/s=
=qWGo
-----END PGP SIGNATURE-----
 
B

Byron

Hi Travis,

You want to use forward slashes with your file names. Backslashes are
used for special character commands, such as "/t" for <tab>, etc.

For Windows:
c:/aFolder/testDocument.txt

For Unix / Linux
/aFolder/testDocument.txt

If you need a relative path, with no drive specified (for Windows), use:
/aFolder/testDocument.txt

Hope this helps,

Byron
 
B

Byron

Opps, correction. "\t" is for <tab> -- I had the slash going the wrong
direction.

Byron
---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top