files,folders,paths
ecu_jon
hayesjdno3 at yahoo.com
Mon Feb 14 05:10:33 EST 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.rmtree(destination)
> else:
> os.unlink(destination)
> shutil.copytree(source, destination)
> return
>
> 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().
>
> DaveA
i thought i had it. i think im going to sleep on it.
here is what im working with right now. jsut trying to make folders
stuff work.
def backupall():
week = weekChoice()
weekstr = "week"+str(week)
source = source1() #was backupdir
destination = destination1() #was remotedir
#destinationweek = os.path.join(destination, weekstr)
for (path, dirs, files) in os.walk(source):
for fname in dirs:
os.chdir(path)
leftover = os.getcwd().replace(source, '')
#print "leftover is:",leftover
currentdir = destination+leftover
if not os.path.isdir(currentdir):
print "leftover is:",leftover
print "currentdir1:",currentdir
print "i should copy teh
folderz",os.path.join(currentdir,fname)
os.mkdir(os.path.join(currentdir,fname),0755)
it is not making the top level folder, then tries to create deeper
folders and fails.
part of the traceback.
os.mkdir(os.path.join(currentdir,fname),0755)
WindowsError: [Error 3] The system cannot find the path specified: 'C:\
\Users\\jon\\backup2\\week2\\configs\\squid_files'
More information about the Python-list
mailing list