hayesjdno3 at yahoo.com
Mon Feb 14 10:53:34 CET 2011
On Feb 14, 4:43 am, Dave Angel <da... at ieee.org> wrote:
> On 01/-10/-28163 02:59 PM, ecu_jon wrote:
> > this is a reply to both Dave Angel and Ben Finney. this version of
> > testing i think incorperates what you guys are saying.
> > <a href="http://thanksforallthefish.endofinternet.net/
> > testing1.py">testin1.py</a>
> > except maybe the os.join.path in the last function.
> > here is the traceback
> > Traceback (most recent call last):
> > File "I:\college\spring11\capstone-project\testing.py", line 88, in
> > <module>
> > backupall()
> > File "I:\college\spring11\capstone-project\testing.py", line 84, 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: '//Mothera/week2\\jonI:\
> > \college\\spring11\\capstone-project\\changelog.txt'
> > it looks like it needs os.walk and the other for line to dig through
> > the folders.
> > this being the whole path
> > I:\\college\\spring11\\capstone-project\\changelog.txt of source.
> Simplify the code.
> def weekChoice()
> return 1 + (datetime.now().day -1) // 7 #weeks go from 1 to 5
> def backupall():
> source = source1()
> destination = destination2()
> print "copy tree ", source, destination
> if os.path.exists(destination):
> if os.path.isdir(destination):
> shutil.copytree(source, destination)
> All that nonsense with curdir was messing up your thinking.
> I'm not going to try to debug your destination2() function, but I would
> point out that when you use os.path.join(), please let it do the work
> for you. It takes any number of arguments, and those arguments should
> not have extra slashes or backslashes in them. The leading slashes are
> okay for the first node, if you want a unc.
> It would have been much easier if you had made source and destination
> arguments to the backupall() function. It then might have become clear
> that it's simply copytree(), with the extra requirement of deleting
> whatever used to be there.
> Now if you aren't allowed to delete what was already there, then you
> can't use copytree, and need to start over with os.walk().
and dest2 was me trying different ways to write to the sever, unc or
mounted drive. that's for later :P
i missed this "as missing parent directories."
shutil.copytree(src, dst[, symlinks=False[, ignore=None]])¶
Recursively copy an entire directory tree rooted at src. The
destination directory, named by dst, must not already exist; it will
be created as well as missing parent directories.
so for testing i did the copy once. deleted the files in top folder,
and deleted a folder deeper in.
gave error when tried to copytree the deeper in folder.
is there something like mkdir?
More information about the Python-list