Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > files,folders,paths

Reply
Thread Tools

files,folders,paths

 
 
ecu_jon
Guest
Posts: n/a
 
      02-14-2011
On Feb 13, 6:39*pm, Ben Finney <(E-Mail Removed)> wrote:
> ecu_jon <(E-Mail Removed)> writes:
> > can you give an example of how to build a folder name, maybe as a
> > string, with parts of it as variables, that have to be strung
> > together. like x = "//servername/+variable+"/"+variable+"/"

>
> * * import os.path
>
> * * infile_path = os.path.join(["//servername", start_dir, other_dir])
>
> Read the documentation for ‘os.path.join’. It's fundamental if you're
> working with filesystem paths.
>
> > when i did something liek that the end result string was like
> > //servername/folder/folder\file and i got an error

>
> That path should work on MS Windows. If you want us to comment on the
> error, you'll need to show the code here *and* the error traceback.
>
> --
> *\ * * * *“If this is your first visit to the USSR, you are welcome to |
> * `\ * * * * * * * * * * * * * * * * * * * * *it.” —hotel room, Moscow |
> _o__) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *|
> Ben Finney


here take a look.
http://thanksforallthefish.endofinternet.net/testing.py
the output looks like
.....
folder to copy = \\\\Mothera\\jon\week2
file to copy: C:\Users\jon\backup\configs\apache2.conf \\\\Mothera\\jon
\week2\configs\apache2.conf
folder to copy = \\\\Mothera\\jon\week2\configs
.....#some lines ommited for brevity.
 
Reply With Quote
 
 
 
 
ecu_jon
Guest
Posts: n/a
 
      02-14-2011
On Feb 13, 8:29*pm, Ben Finney <(E-Mail Removed)> wrote:
> ecu_jon <(E-Mail Removed)> writes:
> > here take a look.
> >http://thanksforallthefish.endofinternet.net/testing.py

>
> I think you're confusing yourself by shoving lots of experimental lines
> into a large program and not isolating the problem. I see that you are
> trying lots of different ways of doing the same thing, and commenting
> some lines out arbitrarily.
>
> Instead, focus on the issue that's causing you confusion: constructing a
> filesystem path and testing whether it exists.
>
> Make a *minimal* program that shows the problem you're having. Post it
> *here* (that's why it's important that it be minimal), along with the
> exact error traceback you get from Python when you run it.
>
> Once you have something minimal that we, too, can run, we can comment
> better on its behaviour.
>
> --
> *\ * * * *“Members of the general public commonly find copyright rules |
> * `\ * * * *implausible, and simply disbelieve them.” —Jessica Litman, |
> _o__) * * * * * * * * * * * * * * * * * * * * * * *_Digital Copyright_ |
> Ben Finney


this thing evolved i piece a a time. i got help from the wxpython
people, and now that code has been stable for weeks.

the function weekChoice came after talking to 2 CS grad studenst for 2
hours. deciding how to decide what week to pick. it seems to be solid.
was picking week 1 up till 12:02 when i tested it on the 8th, then
went to week 2.

getusername probably should be unfunctionalized, and maybe dropped
completely.

homeDir is good on the 3 differnt platforms i have tested it on,
linux, xp and 7. Ubuntu returned /home/name, 7 returned c:\Users\name
\, xp returned c:\docs and settings\name\app data\ or something close
to that.

in version 011, source1 and destination1 worked fine. selectivly
coping files or folders as needed.

backupall has been volatile, but relatively stable last 2 weeks. in
version 011, it does the if not folder and file detection. in version
12a, it does not. all of the functions cascade so im not really sure
how i could cut something out, with out serious rewrite. i already did
shrink it by gutting the wxpython parts. after uncommenting the 2
lines
shutil.copytree(os.getcwd(), destination+leftover)
shutil.copy2(filesource, filedest1)
i get this as an traceback
folder to copy = \\\\Mothera\\jon\week2

Traceback (most recent call last):
File "I:\college\spring11\capstone-project\testing.py", line 86, in
<module>
backupall()
File "I:\college\spring11\capstone-project\testing.py", line 73, in
backupall
shutil.copytree(os.getcwd(), destination+leftover)
File "C:\Python27\lib\shutil.py", line 174, in copytree
os.makedirs(dst)
File "C:\Python27\lib\os.py", line 150, in makedirs
makedirs(head, mode)
File "C:\Python27\lib\os.py", line 150, in makedirs
makedirs(head, mode)
File "C:\Python27\lib\os.py", line 150, in makedirs
makedirs(head, mode)
File "C:\Python27\lib\os.py", line 157, in makedirs
mkdir(name, mode)
WindowsError: [Error 161] The specified path is invalid: '\\\\\\\\'
 
Reply With Quote
 
 
 
 
ecu_jon
Guest
Posts: n/a
 
      02-14-2011
On Feb 14, 12:12*am, Ben Finney <(E-Mail Removed)> wrote:
> ecu_jon <(E-Mail Removed)> writes:
> > On Feb 13, 8:29*pm, Ben Finney <(E-Mail Removed)> wrote:
> > > Instead, focus on the issue that's causing you confusion:
> > > constructing a filesystem path and testing whether it exists.

>
> > > Make a *minimal* program that shows the problem you're having. Post it
> > > *here* (that's why it's important that it be minimal), along with the
> > > exact error traceback you get from Python when you run it.

>
> > > Once you have something minimal that we, too, can run, we can comment
> > > better on its behaviour.

>
> > this thing evolved i piece a a time.

>
> I don't doubt it. But clearing up confusion over what a big wad of code
> does is best done by trying to isolate the problem into a small piece of
> code.
>
> > i got help from the wxpython people, and now that code has been stable
> > for weeks.

>
> > the function weekChoice came after talking to 2 CS grad studenst for 2
> > hours. deciding how to decide what week to pick. it seems to be solid.
> > was picking week 1 up till 12:02 when i tested it on the 8th, then
> > went to week 2.

>
> This all sounds as though you're doing ball-of-mud programming: keep
> throwing more code at the program, and whatever sticks must stay there
> forever without understanding what it's doing.
>
> That's a bad idea. I hope you can already see why.
>
> Really, please make a new, minimal, complete example that still exhibits
> the specific confusing behaviour, and *post it in a message* (not at a
> URL), so we can see the problem in isolation. If it's more than a dozen
> lines, it's doing too much for the problem you're talking about here.
>
> --
> *\ * * * *“We cannot solve our problems with the same thinking we used |
> * `\ * * * * * * * * * * * * * when we created them.” —Albert Einstein |
> _o__) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *|
> Ben Finney


well it seems not to be the difference between versions 11,12,12a.
it works great on my linux box. i get all these errors on the windows
boxes.
i think it has to do with the folder name, and strings etc. got to se
if i can use os.join.path for the whole naming.
 
Reply With Quote
 
ecu_jon
Guest
Posts: n/a
 
      02-14-2011
i think i got it. my dirlist wasn't the right way to go, i needed to
iterate thu what oswalk was giving me in dirs, and files. not
bruteforce strip to a string. i have been starting at an early version
and a later version for the last 4 hours or so, and i think i have it
this only handles the folders. i wanted to try out the logic before i
doubled up and parsed files too. substitute this in for the backup
function. and for now the source and destination functions are in this
to. ill clean it up once i test it more.
backupdir = os.path.join(homedir, "backup")
remotedir = os.path.join(homedir, "backup2")
weekstr = "week"+str(week)
remotedirweek = os.path.join(remotedir, weekstr)
print
'################################################# ###############'
for (path, dirs, files) in os.walk(backupdir):
print "current path is : ",path
print "current dir is : ",dirs
print "current files are: ",files
for fname in dirs:
os.chdir(path)
leftover = os.getcwd().replace(backupdir, '')
print "leftover is:",leftover
print "remotedirweek is:",remotedirweek
currentdir1 = remotedirweek+leftover
if not os.path.isdir(currentdir1):
print "currentdir1:",currentdir1
print "i should copy teh
folderz",os.path.join(currentdir1,fname)

shutil.copytree(os.getcwd(),os.path.join(currentdi r1,fname))


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments