473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Files in unix and windows

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.
Jul 18 '05 #1
3 2041
Which extra (back)slashes do you mean? Do you mean that os.path.abspath
strips the trailing separator characters from its argument?
os.path.abspath("../../../../etc/") '/etc' os.path.normpath("./") '.'

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
myabspath('../../../../../etc/') '/etc/' myabspath('../../../../../etc')

'/etc'

Jeff

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

iD8DBQFBJ0ibJd01MZaTXX0RAg4mAJ9SUjjg8rDt4OY1YvVaNw 8lSx9vAQCbBbk1
E6QV8mAC602+zN7/r8j3+/s=
=qWGo
-----END PGP SIGNATURE-----

Jul 18 '05 #2
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
---
Travis James Kleeburg wrote:
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.

Jul 18 '05 #3
Opps, correction. "\t" is for <tab> -- I had the slash going the wrong
direction.

Byron
---
Byron wrote:
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
---
Travis James Kleeburg wrote:
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.

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jubril Oyesiji | last post by:
Does anyone have an idea about how to convert Java Class files into Windows Executables (.Exe) except writing a Batch file
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
5
by: Rothariger | last post by:
Hello.... i want to know if its posible to rename multiple files like windows does.. example: file zzzzzzz.doc file asdasd.doc file esfsefse.doc
3
by: anand.ba | last post by:
Hi, I need to port some C code from UNIX SGI to Windows (MS VC++ compiler). The following header files arent available in windows: #include <sys/param.h> #include <sys/ioctl.h> #include...
1
by: SagharAyyaz | last post by:
Hi all, I am new to google groups. I want to copy files from Windows to Linux Server through VC++ program. Can any body help me? I don't know, am I in the right group or not but hopefully I...
0
by: Rainer Lehrig | last post by:
Hello, we have build a library for our Open Source SCADA project http://pvbrowser.org The library supports Linux/Unix, Windows and OpenVMS. The doxygen documentation of the library can be...
1
by: destiny1 | last post by:
what is the API to acess/fetch files of windows using python on unix?
0
by: db2readlog | last post by:
Hi, I need to read the DB2 transaction log files on Windows XP using DB2 API in a program. I need to read the log files for INSERT/UPDATE/DELETE operations. Can anyone please help me with this. ...
3
by: sekhar.mekala | last post by:
Hello, I am a DB2 DBA on IBM Mainframe environment. I recently started learning DB2 on Unix/Windows environment. Can any one answer the following questions: 1. What is the qualifier that is...
0
by: olneybucks | last post by:
I have two audio files and I want to fade between the two audio files in windows mobile 6.0? Looking at the sound api it does not appear possible..
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.