How to delete this file ???

D

DCK

Hello

I've path to file, which look like this:
\\COMPUTER\D$\C++\FILE_TO_DELETE.JPG
This path was generated by os.path.walk() function. When i try to delete
this file, os.remove() can't find it, os.path.fileexists() can't find it :(
I can delete other files (i.e. \\COMPUTER\D$\C\FILE_TO_DELETE.JPG). I guess
there's a problem with this C++ directory (++ exacly). I tried to change it
to C\+\+, but this still not work. I've no idea how to delete this file.

I work under WinNT 4.0 with sp6, python 2.3 with unicode support. I have
adminstrator rights.
Can somebody help me ?
 
G

Gerrit Holl

DCK said:
I've path to file, which look like this:
\\COMPUTER\D$\C++\FILE_TO_DELETE.JPG

What do you mean exactly by: 'looks like'? Is it the full path to the
file? How did you find out?
This path was generated by os.path.walk() function. When i try to delete
this file, os.remove() can't find it, os.path.fileexists() can't find it :(

Does the directory exist, e.g., what does
'os.path.exists('\\computer\d$\c++') give as result? And
'os.path.exists('\\computer\d$')? I think a 'd$' is usually a share in
Windows (not sure), maybe you haven't turned the share on (I'm not sure
what 'mounting' is called in Windows)?
I can delete other files (i.e. \\COMPUTER\D$\C\FILE_TO_DELETE.JPG). I guess
there's a problem with this C++ directory (++ exacly). I tried to change it
to C\+\+, but this still not work. I've no idea how to delete this file.

I work under WinNT 4.0 with sp6, python 2.3 with unicode support. I have
adminstrator rights.
Can somebody help me ?

Maybe. Can you give some more precise information? What is your
os.path.walk command? How does it reach this path?

yours,
Gerrit.

--
169. If he be guilty of a grave fault, which should rightfully deprive
him of the filial relationship, the father shall forgive him the first
time; but if he be guilty of a grave fault a second time the father may
deprive his son of all filial relation.
-- 1780 BC, Hammurabi, Code of Law
 
M

Mark Hammond

DCK said:
Hello

I've path to file, which look like this:
\\COMPUTER\D$\C++\FILE_TO_DELETE.JPG
This path was generated by os.path.walk() function. When i try to delete
this file, os.remove() can't find it, os.path.fileexists() can't find it :(
I can delete other files (i.e. \\COMPUTER\D$\C\FILE_TO_DELETE.JPG). I guess
there's a problem with this C++ directory (++ exacly). I tried to change it
to C\+\+, but this still not work. I've no idea how to delete this file.

I work under WinNT 4.0 with sp6, python 2.3 with unicode support. I have
adminstrator rights.
Can somebody help me ?

Are you sure you have quoted your back-slashes correctly? It works for me:

python -c "import os;print os.path.exists(r'\\eden\e\temp\delme')"
True

Mark.
 
D

Duncan Booth

What do you mean exactly by: 'looks like'? Is it the full path to the
file? How did you find out?


Does the directory exist, e.g., what does
'os.path.exists('\\computer\d$\c++') give as result? And
'os.path.exists('\\computer\d$')? I think a 'd$' is usually a share in
Windows (not sure), maybe you haven't turned the share on (I'm not
sure what 'mounting' is called in Windows)?

You need some raw string quoting there.

os.path.exists(r'\\computer\d$\c++') would check for the existence of a
directory c++ on drive D of the computer named 'computer', provided you
have administrative access to the remote computer. The drive letter shares
c$ (and d$ etc. where there is more than one drive) are created
automatically and are only accessible to administrators. The UNC pathnames
being used mean that there is no need to mount the drive before accessing
it.

os.path.exists(r'\\computer\d$') will return False whether or not the share
exists, however os.path.exists(r'\\computer\d$\\') will return True if the
share exists. Note that you need two trailing backslashes even if you don't
use the raw quoting.

I tried creating a file called FILE_TO_DELETE.JPG in a directory called C++
on a remote machine. I checked the existence of both the file and directory
using os.path.exists, and then removed first the file and then the
directory using os.remove. Both operations worked as expected, so the '+'
character in the filename is not a problem (Python 2.3). I suspect the OP
must have something else wrong, possibly a confusion over backslashes, or
possibly just insufficient access to the C++ directory (just because you
have access to the admin shares doesn't mean you necessarily have full
access to all the directories).
 
D

DCK

Hello again
Really sorry for long time between me letters. All problem gone, after i've
used raw string (r"\\path\to\any\file") Really thanks for all answers :)

Thank's again !
 
P

Peter Hansen

DCK said:
Hello again
Really sorry for long time between me letters. All problem gone, after i've
used raw string (r"\\path\to\any\file") Really thanks for all answers :)

Note that it's almost always better to use forward slashes instead.

In this case, "//path/to/any/file" would work wonderfully, and is much
more readable.

Yes, it does work with Windows. The only time it doesn't is when using
command line programs which interpret the forward slash as an option,
and insist on backslashes.

(An unfortunate additional area is that os.path for Windows normalizes
things to use backslashes, and therefore path comparisons can get a little
tricky if you use forward slashes but aren't careful about normalizing
with os.path.normpath() all the time.)

-Peter
 

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
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top