files,folders,paths
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Feb 13 06:53:06 EST 2011
On Sun, 13 Feb 2011 02:06:15 -0800, ecu_jon wrote:
> i have a samba server at home (acting as my test environment) with one
> of the 'shares' mounted as v: on my windows box. inside of that are 4
> folders week[1-4]. i have created c:\users\name\backup , and put a few
> files/folders in there to test with. please ignore the wxpython parts of
> the script, the last 1/3, that part is functional.
Please don't dump code on us and tell us to ignore parts of it. We're
offering our time and experience without charging you, the least you can
do is take the time to eliminate the irrelevant parts of the code
yourself, and show us the smallest piece of code which demonstrates the
problem.
Doing so will not only demonstrate respect for others, but it might even
help you solve the problem yourself.
> initial test was
> looking good. (in the code, ver011 source1, destination1) coping files/
> folders and not clobbering files. going to version 12a, it seems like it
> is trying to copy the files under the folder, before making the folder.
> or doing the copy2 part before the copytree part. i dont know why it
> works on ver011, and not in ver12a, the only difference being the
> destination.
That's not exactly true, is it? I count at least three other differences:
* facbac-012a.py imports getpass and defines a redundant
getusername function (redundant because all it does is
wrap getpass.getuser);
* it also defines a function destination2 which is different
from destination1, and uses that;
* there's a difference in the call to os.path.isfile;
I don't know if these are relevant.
You say the difference between the script that works and the script that
doesn't is the destination. And then you show an error that appears to be
because the destination doesn't exist:
> Traceback (most recent call last):
> File "I:\college\spring11\capstone-project\facbac-012a.py", line
> 161, in button1Click
> backupall()
> File "I:\college\spring11\capstone-project\facbac-012a.py", line 81,
> in backupall
> shutil.copy2(filesource, filedest1)
> File "C:\Python27\lib\shutil.py", line 127, in copy2
> copyfile(src, dst)
> File "C:\Python27\lib\shutil.py", line 82, in copyfile
> with open(dst, 'wb') as fdst:
> IOError: [Errno 2] No such file or directory: 'V:\\week2\\configs\
> \apache2.conf'
Seems like an open and shut case to me.
> here, apache2.conf = c:\users\name\backup\config\apache2.conf trying to
> copy to v:\week2\config\apache2.conf but there is no v:\week2\config
> as it has not made the config folder yet i think the problem might be
> the \\ in the destination name.
There is no double-backslash in the destination name. Backslashes are
special in Python, and when displaying strings, they are escaped:
>>> s = "x\yz"
>>> len(s)
4
>>> s
'x\\yz'
>>> print s
x\yz
Your suggestion, that the problem is that the config directory doesn't
exist, sounds reasonable to me. Only you can test that, as we don't have
access to your file system.
--
Steven
More information about the Python-list
mailing list